SQL> select to_char(to_date('20060831','yyyymmdd') + interval '1' month,'yyyymmdd') from dual ;
select to_char(to_date('20060831','yyyymmdd') + interval '1' month,'yyyymmdd') from dual
ORA-01839: 指定月份的日期無效
SQL> select to_char(to_date('20060831','yyyymmdd') + interval '2' month,'yyyymmdd') from dual ;
TO_CHAR(TO_DATE('20060831','YY
------------------------------
20061031
SQL> select to_char(to_date('20060831','yyyymmdd') + interval '3' month,'yyyymmdd') from dual ;
select to_char(to_date('20060831','yyyymmdd') + interval '3' month,'yyyymmdd') from dual
ORA-01839: 指定月份的日期無效
SQL> select to_char(to_date('20060831','yyyymmdd') + interval '4' month,'yyyymmdd') from dual ;
TO_CHAR(TO_DATE('20060831','YY
------------------------------
20061231
SQL> select to_char(to_date('20060131','yyyymmdd') + interval '1' month,'yyyymmdd') from dual ;
select to_char(to_date('20060131','yyyymmdd') + interval '1' month,'yyyymmdd') from dual
ORA-01839: 指定月份的日期無效
SQL> select to_char(to_date('20060130','yyyymmdd') + interval '1' month,'yyyymmdd') from dual ;
select to_char(to_date('20060130','yyyymmdd') + interval '1' month,'yyyymmdd') from dual
ORA-01839: 指定月份的日期無效
SQL> select to_char(to_date('20060129','yyyymmdd') + interval '1' month,'yyyymmdd') from dual ;
select to_char(to_date('20060129','yyyymmdd') + interval '1' month,'yyyymmdd') from dual
ORA-01839: 指定月份的日期無效
SQL> select to_char(to_date('20060128','yyyymmdd') + interval '1' month,'yyyymmdd') from dual ;
TO_CHAR(TO_DATE('20060128','YY
------------------------------
20060228
如果是日期中的日在下一(n)個月中不存在,就會報出錯誤,而用add_months是沒有問題的。
以上問題在9i和10g上都實驗過!