--本周
select trunc(sysdate,'d')+1 from dual;
select trunc(sysdate,'d')+7 from dual;
--本月
select trunc(sysdate,'mm') from dual;
select last_day(trunc(sysdate)) from dual;
--本季
select trunc(sysdate,'Q') from dual;
select add_months(trunc(sysdate,'Q'),3)-1 from dual;
--本年
select trunc(sysdate,'yyyy') from dual;
select add_months(trunc(sysdate,'yyyy'),12)-1 from dual;
-- 获取上月的开始时间和结束时间
select to_char(to_date(to_char(add_months(sysdate,-1),'yyyy-mm'),'yyyy-mm'),'yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(to_date(to_char(sysdate,'yyyy-mm'),'yyyy-mm'),'yyyy-mm-dd hh24:mi:ss') from dual;
-- 获取前一天的开始时间和结束时间
select to_char(to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd'),'yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'),'yyyy-mm-dd hh24:mi:ss') from dual;
-- 获取上一个小时的开始时间和结束时间
select to_date(to_char(sysdate,'yyyy-mm-dd')||(to_char(sysdate,'hh24')-1),'yyyy-mm-dd hh24') from dual;
select to_date(to_char(sysdate,'yyyy-mm-dd')||(to_char(sysdate,'hh24')),'yyyy-mm-dd hh24') from dual;