如果times 字段保存了日期+时间,那么可以 where TIMES >= trunc(sysdate-1) and times < trunc(sysdate)如果times 字段只保存了日期,那么可以 where TIMES = trunc(sysdate-1)
用变量 v_date :=sysdate-1;
可以用PL/SQL,常量SYSDATE,只读取一次SYSDATE,用where TIMES = trunc(sysdate-1)就可以了。 楼主看效率行不行。
建议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'))
where TIMES >= trunc(sysdate-1) and times < trunc(sysdate)如果times 字段只保存了日期,那么可以
where TIMES = trunc(sysdate-1)
v_date :=sysdate-1;
楼主看效率行不行。
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'))
2. 修改where 部分为:
WHERE times >= TRUNC(SYSDATE) - 1
AND times < TRUNC(SYSDATE)