Oracle怎麼獲取某個日期之前的資料
阿新 • • 發佈:2019-01-14
這幾天工作經常需要查詢某天之前的資料,整理了兩個最常用的方法(假設欄位的名稱為table_date):
to_date:
select * from emp where table_date>to_date(‘2018-11-22,yyyy-mm-dd’);
to_char:
select * from test where to_char(table_time, ‘yyyy-mm-dd’) >= ‘2018-11-22’
若要獲取某一時間段的資料,可以使用between或者’>’ ‘<’ '='號實現。
eg:
select * from table_name t where t.table_date between to_date(‘2018-11-20 00:00:00’,‘yyyy-mm-dd hh24:mi:ss’) and to_date(‘2018-11-22 23:59:59’,‘yyyy-mm-dd hh24:mi:ss’)
or:
select * from table_name where t.table_date >= to_date(‘2015-10-20 00:00:00’,‘yyyy-mm-dd hh24:mi:ss’) and t.table_date <= to_date(‘2015-10-20 23:59:59’,‘yyyy-mm-dd hh24:mi:ss’)