where to_char(TIMES,'yyyymmdd') = to_char(sysdate-1,'yyyymmdd')
现在是用上面这种方式查前一天产生的记录,但由于数据量巨大,所以超慢,有没有好的写法,请教大侠了~~~

解决方案 »

  1.   

    如果times 字段保存了日期+时间,那么可以
    where TIMES >= trunc(sysdate-1) and times < trunc(sysdate)如果times 字段只保存了日期,那么可以
    where TIMES = trunc(sysdate-1) 
      

  2.   

    用变量
     v_date :=sysdate-1;
      

  3.   

    可以用PL/SQL,常量SYSDATE,只读取一次SYSDATE,用where TIMES = trunc(sysdate-1)就可以了。
    楼主看效率行不行。
      

  4.   

    建议1.假如times已经建立索引,则可以
      where times>to_date(to_char(sysdate-1,'yyyymmdd'),'yyyymmdd')
      and times<to_date(to_char(sysdate,'yyyymmdd'),'yyyymmdd')
      此条件意思:取从昨天零点开始到今天零点结束的记录建议2.对times列做函数索引:  
    create index ix_table_name_times on table_name(to_char(times,'yyyymmdd'))
      

  5.   

    实在没办法, 就建个 函数index,  to_char(TIMES,'yyyymmdd')  这个东西上建index
      

  6.   

    where times between trunc(sysdate-1) and trunc(sysdate) -1/24/60/60
      

  7.   

    1. 保证 times 上建立了索引,如果是联合索引,则考虑将该字段放到第一位;
    2. 修改where 部分为:
       WHERE times >= TRUNC(SYSDATE) - 1 
         AND times <  TRUNC(SYSDATE)