oracle interval日期函式的bug!

zhouwf0726發表於2019-03-11

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上都試驗過!


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242198/,如需轉載,請註明出處,否則將追究法律責任。

相關文章