如果对acc_begin_time没有做基于function的索引,而是做了B-Tree索引, 可以改成: and bnr.acc_begin_time between to_date('20091001000000','yyyymmddhh24miss') and to_date('20091001235959','yyyymmddhh24miss')
UP,楼上的说的对 and to_char(bnr.acc_begin_time,'yyyy-MM-dd')='2009-10-01' 改成 and bnr.acc_begin_time=to_date('2009-10-01','yyyy-mm-dd') 试试效率如何
如果acc_begin_time有时分秒,那么大部分row将不能被检索出来!
是的,我的acc_begin_time是带有时分秒的。
不一定非要用等值啊,between ... and...什么的不就可以了 另外注意绑定变量
and bnr.acc_begin_time=to_date('2009-10-01','yyyy-mm-dd') 改下就好了 and bnr.acc_begin_time>=to_date('2009-10-01','yyyy-mm-dd HH24:MI:SS') AND bnr.acc_begin_time<to_date('2009-10-02','yyyy-mm-dd HH24:MI:SS')
where 条件改成 bnr.acc_begin_time>=to_date('2009-10-01 00:00:00','yyyy-mm-dd HH24:MI:SS') AND bnr.acc_begin_time<to_date('2009-10-02 00:00:00','yyyy-mm-dd HH24:MI:SS') 肯定比LZ的方法要快。除非你建了to_char函数索引。
可以改成:
and bnr.acc_begin_time between to_date('20091001000000','yyyymmddhh24miss') and to_date('20091001235959','yyyymmddhh24miss')
如果你的日期字段是有索引的,那么就将右边的字符串变为日期
and to_char(bnr.acc_begin_time,'yyyy-MM-dd')='2009-10-01'
改成
and bnr.acc_begin_time=to_date('2009-10-01','yyyy-mm-dd')
试试效率如何
是的,我的acc_begin_time是带有时分秒的。
另外注意绑定变量
改下就好了
and bnr.acc_begin_time>=to_date('2009-10-01','yyyy-mm-dd HH24:MI:SS')
AND bnr.acc_begin_time<to_date('2009-10-02','yyyy-mm-dd HH24:MI:SS')
bnr.acc_begin_time>=to_date('2009-10-01 00:00:00','yyyy-mm-dd HH24:MI:SS')
AND bnr.acc_begin_time<to_date('2009-10-02 00:00:00','yyyy-mm-dd HH24:MI:SS')
肯定比LZ的方法要快。除非你建了to_char函数索引。