年計算
-- 下一年/年加1
select sysdate, sysdate+numtoyminterval(1,'year') from dual
select sysdate, add_months(sysdate,12) from dual
-- 上一年/年減1
select sysdate, sysdate-numtoyminterval(1,'year') from dual
select sysdate, add_months(sysdate,-12) from dual
月計算
-- 下一月/月加1
select sysdate, sysdate+numtoyminterval(1,'month') from dual
select sysdate, add_months(sysdate,1) from dual
-- 上一月/月減1
select sysdate, sysdate-numtoyminterval(1,'month') from dual
select sysdate, add_months(sysdate,-1) from dual
天計算
-- 下一天/天加1
select sysdate, sysdate+1 from dual
select sysdate, sysdate+numtodsinterval(1,'day') from dual
-- 上一天/天減1
select sysdate, sysdate-1 from dual
select sysdate, sysdate-numtodsinterval(1,'day') from dual
小時計算
-- 下一小時/小時加1
select sysdate, sysdate+1/24 from dual
select sysdate, sysdate+numtodsinterval(1,'hour') from dual
-- 上一小時/小時減1
select sysdate, sysdate-1/24 from dual
select sysdate, sysdate-numtodsinterval(1,'hour') from dual
分鐘計算
-- 下一分鐘/分鐘加1
select sysdate, sysdate+1/24/60 from dual
select sysdate, sysdate+numtodsinterval(1,'minute') from dual
-- 上一分鐘/分鐘減1
select sysdate, sysdate-1/24/60 from dual
select sysdate, sysdate-numtodsinterval(1,'minute') from dual
秒計算
-- 下一分鐘/分鐘加1
select sysdate, sysdate+1/24/60/60 from dual
select sysdate, sysdate+numtodsinterval(1,'second') from dual
-- 上一分鐘/分鐘減1
select sysdate, sysdate-1/24/60/60 from dual
select sysdate, sysdate-numtodsinterval(1,'second') from dual
trunc()函式
-- 當天 0時0分0秒
select sysdate, trunc(sysdate) from dual
select sysdate, trunc(sysdate,'dd') from dual
-- 當月第一天 0時0分0秒
select sysdate, trunc(sysdate, 'mm') from dual
-- 返回當年第一天 0時0分0秒
select sysdate, trunc(sysdate,'yy') from dual
select sysdate, trunc(sysdate,'yyyy') from dual
-- (星期天)返回當前星期第一天 0時0分0秒
select sysdate, trunc(sysdate,'d') from dual
-- 當前小時 0分0秒
select sysdate, trunc(sysdate, 'hh') from dual
-- 當前分鐘 0秒 (TRUNC()函式沒有秒的精確)
select sysdate, trunc(sysdate, 'mi') from dual