當月數據
- select * from table t
- where t.create_time >=TRUNC(SYSDATE, 'MM')
- and t.create_time<=last_day(SYSDATE)
select * from table t
where t.create_time >=TRUNC(SYSDATE, 'MM')
and t.create_time<=last_day(SYSDATE)
當年數據
- select * from table t
- where t.create_time >=trunc(sysdate,'YYYY')
- and t.create_time<=add_months(trunc(sysdate,'YYYY'),12)-1
select * from table t
where t.create_time >=trunc(sysdate,'YYYY')
and t.create_time<=add_months(trunc(sysdate,'YYYY'),12)-1
本周(國外周日為一個星期第一天)
- where t.create_time >=trunc(sysdate,'day')+1 and t.create_time<=trunc(sysdate,'day')+6
where t.create_time >=trunc(sysdate,'day')+1 and t.create_time<=trunc(sysdate,'day')+6
本周(國內周一為一個星期第一天)
- where t.create_time >=trunc(next_day(sysdate-8,1)+1) and t.create_time<=trunc(next_day(sysdate-8,1)+7)+1
--加法
select sysdate,add_months(sysdate,12) from dual;--加1年
select sysdate,add_months(sysdate,1) from dual;--加1月
select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual; --加1星期
select sysdate,to_char(sysdate+1,'yyyy-mm-dd HH24:MI:SS') from dual; --加1天
select sysdate,to_char(sysdate+1/24,'yyyy-mm-dd HH24:MI:SS') from dual; --加1小時
select sysdate,to_char(sysdate+1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual; --加1分鐘
select sysdate,to_char(sysdate+1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual; --加1秒
--減法
select sysdate,add_months(sysdate,-12) from dual; --減1年
select sysdate,add_months(sysdate,-1) from dual; --減1月
select sysdate,to_char(sysdate-7,'yyyy-mm-dd HH24:MI:SS') from dual; --減1星期
select sysdate,to_char(sysdate-1,'yyyy-mm-dd HH24:MI:SS') from dual; --減1天
select sysdate,to_char(sysdate-1/24,'yyyy-mm-dd HH24:MI:SS') from dual; --減1小時
select sysdate,to_char(sysdate-1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual; --減1分鐘
select sysdate,to_char(sysdate-1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual; --減1秒