这几天工作经常需要查询某天之前的数据,整理了两个最常用的方法(假设字段的名称为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’)