查询一小时
select concat(to_char(sysdate,'yyyy-mm-dd ')||(to_char(sysdate,'hh24')-1),':00:00') start_time,concat(to_char(sysdate,'yyyy-mm-dd hh24'),':00:00') end_time from dual
结果:
查询前一天
select to_char(sysdate-1,'yyyy-mm-dd ')||'00:00:00' start_time,to_char(sysdate-1,'yyyy-mm-dd ')||'23:59:59' end_time from dual
结果:
查询前一个月
select concat(to_char(sysdate,'yyyy')||to_char(add_months(sysdate,-1), '-MM-'),'01 00:00:00')start_time,
concat(to_char(sysdate,'yyyy')||to_char(add_months(sysdate,-1), '-MM-')||to_char(LAST_DAY(sysdate),'dd '),'23:59:59') end_time from dual
结果:
查询前一年
select extract(year from sysdate)-1||'-01-01 00:00:00' start_time,concat(extract(year from sysdate)-1||'-12-'||to_char(LAST_DAY(sysdate),'dd '),'23:59:59') end_time
from dual
结果: