Oracle日期计算之INTERVAL

在计算月份的时候除了add_months,还可用INTERVAL:

 

Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 
Connected as xxpo
 
SQL> 
SQL> SELECT to_char(SYSDATE,'YYYY/MM/DD HH24:MI:SS') now FROM dual;
 
NOW
-------------------
2011/05/20 06:22:00
SQL> SELECT to_char(add_months(SYSDATE,-1),'YYYY/MM/DD HH24:MI:SS') "1 month before" FROM dual;
 
1 month before
-------------------
2011/04/20 06:22:02
SQL> SELECT to_char(SYSDATE + INTERVAL '-1' MONTH,'YYYY/MM/DD HH24:MI:SS') "1 month before" FROM dual;
 
1 month before
-------------------
2011/04/20 06:22:04
SQL> SELECT to_char(SYSDATE + INTERVAL '1-1' YEAR TO MONTH,'YYYY/MM/DD HH24:MI:SS') "1 year and 1 month later" FROM dual;
 
1 year and 1 month later
------------------------
2012/06/20 06:22:06
SQL> SELECT to_char(SYSDATE + INTERVAL '-1-1' YEAR TO MONTH,'YYYY/MM/DD HH24:MI:SS') "1 year and 1 month before" FROM dual;
 
1 year and 1 month before
-------------------------
2010/04/20 06:22:08
 
SQL> 


原文链接: http://blog.csdn.net/t0nsha/article/details/6435365

你可能感兴趣的:(Oracle日期计算之INTERVAL)