我的判断语句是,把某一天的数据查询出来,and to_char(bnr.acc_begin_time,'yyyy-MM-dd')='2009-10-01'。大家帮我优化下,我的是存储过程,估计绑定变量时用不上了吧!

解决方案 »

  1.   

    如果对acc_begin_time没有做基于function的索引,而是做了B-Tree索引,
    可以改成:
    and bnr.acc_begin_time between to_date('20091001000000','yyyymmddhh24miss') and to_date('20091001235959','yyyymmddhh24miss') 
      

  2.   

    存储过程为什么就不能用绑定变量呢?-------->就你的SQL如果非要那么写,不使用绑定变量,而传入常量是很错误的
    如果你的日期字段是有索引的,那么就将右边的字符串变为日期
      

  3.   

    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')
    试试效率如何
      

  4.   

    如果acc_begin_time有时分秒,那么大部分row将不能被检索出来!
      

  5.   


    是的,我的acc_begin_time是带有时分秒的。
      

  6.   

    不一定非要用等值啊,between ... and...什么的不就可以了
    另外注意绑定变量
      

  7.   

    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')
      

  8.   

    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函数索引。
      

  9.   

    写SQL的基本法则: 不要对字段进行左值运算,否则用不上索引。
      

  10.   

    Lvalue即左值,说语言的都知道啊,即操作符左边的值,类似地,Rvalue即右值