oraclebetweenand邊界問題
--創建一個表
create table test_hsj(
id int primary key,
num varchar2(12),
regDate date
)
select * from test_hsj;
--插入測試數據
insert into test_hsj values(1,'1', to_date('2015-05-01','yyyy-MM-dd'))
insert into test_hsj values(2,'2', to_date('2015-06-01','yyyy-MM-dd'))
insert into test_hsj values(3,'3', to_date('2015-05-11','yyyy-MM-dd'))
insert into test_hsj values(4,'4', to_date('2015-05-01','yyyy-MM-dd'))
insert into test_hsj values(5,'5', to_date('2015-06-21','yyyy-MM-dd'))
insert into test_hsj values(6,'6', to_date('2015-06-11','yyyy-MM-dd'))
insert into test_hsj values(7,'7', to_date('2016-06-11','yyyy-MM-dd'))
insert into test_hsj values(8,'8', to_date('2014-04-01','yyyy-MM-dd'))
--查詢驗證,日期在 5 月到6月份之間的數據 如果轉換為日期的時候,只有年月的時候會默認取1號 between and 會包含兩端 包含兩端
--1 結論:對於日期類型 between and 包括 >= and <=
select * from test_hsj where regdate between to_date('2015-05','yyyy-MM') and to_date('2015-06','yyyy-MM')
--如果只有年月 則只會去 1號
select to_date('2015-05','yyyy-MM') from dual
--如果只有年,那麼回去當前月份 的1 號
select to_date('2014','yyyy') from dual
--2 結論: 對於數值類型 between and 等效 >= and <=
select * from test_hsj where id between 1 and 5;
--3 結論: 對於字符類型 between and 等效 >= and <=
select * from test_hsj where num between '1' and '5';
--總結論: 對於orcle數據庫 between and 等效 >= and <=