oracle中取今天的数据,之前使用到where to_char(t.t_created_tm,
oracle中取今天的数据,之前使用到where to_char(t.t_created_tm, 'yyyy-mm-dd')= to_char(sysdate, 'yyyy-mm-dd');
这种方式效率低下,而且对t.t_created_tm即使建了索引,但是因为对他进行了函数封装后比较,查询时索引也用不上。
这里介绍可以使用trunc(sysdate)=当天来比较过滤数据,,达到取今天数据的效果。
select trunc(sysdate) from dual;
--trunc(sysdate)
2013/1/5
下面的方法比较好。
select * from tbl_step t where t.t_create_tm >= trunc(sysdate);
如果取当年的数据
select * from tbl_step t where t.t_create_tm >= trunc(sysdate,'yyyy');
当月的数据
select * from tbl_step t where t.t_create_tm>=trunc(sysdate, 'mm') and t.t_create_tm