【Oracle】使用Interval求一天前、一月前、一年前的时间

SQL:

select
    to_char((sysdate-interval'1'day),'yyyy-mm-dd') as yesterday,
    to_char((sysdate-interval'1'month),'yyyy-mm-dd') as oneMonthAgo,
    to_char((sysdate-interval'1'year),'yyyy-mm-dd') as oneYearAgo
from dual

执行效果:

SQL> select
  2      to_char((sysdate-interval'1'day),'yyyy-mm-dd') as yesterday,
  3      to_char((sysdate-interval'1'month),'yyyy-mm-dd') as oneMonthAgo,
  4      to_char((sysdate-interval'1'year),'yyyy-mm-dd') as oneYearAgo
  5  from dual;

YESTERDAY            ONEMONTHAGO          ONEYEARAGO
-------------------- -------------------- --------------------
2021-10-19           2021-09-20           2020-10-20

END

posted @ 2021-10-20 21:13  逆火狂飙  阅读(1006)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东