当查询的表字段类型为DATE时,查询跟日期相关的数据:
select trunc(sysdate),to_date((to_char(sysdate,'yyyy-mm-dd')||'23:59:59'),'YYYY-MM-DD:HH24:MI:SS') from dual;-----当天
select TRUNC(NEXT_DAY(SYSDATE-8,1)+1),to_date((to_char(TRUNC(NEXT_DAY(SYSDATE-8,1)+7),'yyyy-mm-dd')||'23:59:59'),'YYYY-MM-DD:HH24:MI:SS') from dual t ---本周
select trunc(sysdate,'mm'),add_months(trunc(sysdate,'mm'),1)-1 from dual t;-----本月
SELECT to_char(TRUNC(SYSDATE, 'Q'), 'YYYY-MM-DD'),to_char(add_months(TRUNC(SYSDATE, 'Q'), +3)-1, 'YYYY-MM-DD') FROM dual;---本季度
select trunc(sysdate,'YYYY'),add_months(trunc(sysdate,'YYYY'),12)-1 from dual t; -----本年
以下是参考:
Oracle 查询今日、昨日、本周、本月和本季度的所有记录
1.字段类型为date
今日
select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd')
昨日
select * from 表名 where to_char(字段名,'dd')= to_char(sysdate-1,'dd')
本周
select * from 表名 where to_char(字段名,'iw')=to_char(sysdate,'iw')
本月
select * from 表名 where to_char(字段名,'mm')=to_char(sysdate,'mm')
本季度
select * from 表名 where to_char(字段名,'q')=to_char(sysdate,'q')
2. 字段类型为varchar2,格式要与格式化的样式匹配
今日
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate,'dd')
昨日
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate-1,'dd')
本周
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'iw')=to_char(sysdate,'iw')
本月
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'mm')=to_char(sysdate,'mm')
本季度
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'q')=to_char(sysdate,'q')