oracle 如何查询在一个日期区间的中的数据?

2024-11-19 06:45:00
推荐回答(3个)
回答(1):

oracle 查询日期区间内的数据一般最常用的就是between and 和>=,<=(或者不要等号)了;
举例:select * from tablename t where t.日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
或者:
select * from tablename where t.日期列 >= to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and t.日期列 <= to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
如果要查询开区间的数据只需将>= 和<=改为>和<就行。

回答(2):

Select * From a
Where Time Between To_Date('20120827080000', 'yyyymmddhh24miss') And To_Date('20120828080000', 'yyyymmddhh24miss')

Select * From a
Where start Date>=To_Date('20120827080000', 'yyyymmddhh24miss') And
end Date=

回答(3):

select *
from a
where a.time between
(select b.startdate
from b b
where sysdate between startdate and enddate)
and (select b.enddate
from b b
where sysdate between startdate and enddate);