我有一个日期,我想打印该日期的偏移量。我可以这样做:PL/SQL和日期间隔
dbms_output.put_line(to_char(g_startDate - interval '4' month ,'YYYY-MM-DD'));
它工作正常。问题是间隔是可变的。当我尝试这个:
dbms_output.put_line(to_char(g_startDate - interval g_dateOffsetAmt month ,'YYYY-MM-DD'));
我得到一个编译器错误。
我想这可能是因为g_dateOffsetAmt
是integer
所以我尝试这样的:
dbms_output.put_line(to_char(g_startDate - interval to_char(g_dateOffsetAmt) month ,'YYYY-MM-DD'));
虽然我仍然得到编译器错误说:
Error: PLS-00103: Encountered the symbol "TO_CHAR" when expecting one of the following: .) , * @ & | = - + at in is mod remainder not rem => .. or != or ~= >= and or like LIKE2_ LIKE4_ LIKEC_ as between from using || member SUBMULTISET_ The symbol "," was substituted for "TO_CHAR" to continue. Line: 704 Error: PLS-00103: Encountered the symbol "MONTH" when expecting one of the following: . () , * % & | = - + at in is mod remainder not range rem => .. or != or ~= >= and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_ The symbol "." was substituted for "MONTH" to continue. Line: 704
有一些其他的方式来做到这一点?
是的,'add_months'完全正是我想要的。并认为我以前使用它,只是忘了它:(男人我真的需要周末! – FrustratedWithFormsDesigner 2010-11-05 14:21:42
并使用添加月份绕过ORA-01839恼人的问题时使用区间算术在月底,例如' date'2010-03-30' - interval'1'month'。但add_months在月末也有自己的问题,如果你比较'add_months(date'2010-02-27',1)'和'add_months(date'2010-02-28',1)' – 2010-11-05 16:15:38