Why does this SQL query work:
SELECT NEXT_DAY(SYSDATE, 7) FROM DUAL;
NEXT_DAY(SYSDATE,7)
... but does this anonymous PL / SQL block not work?
DECLARE dteExpires DATE; BEGIN dteExpires := NEXT_DAY(SYSDATE, 7); END;
Error at line 1 ORA-01846: not a valid day of the week ORA-06512: at line 4
I do not want to hard code the second parameter for the English name of the day ex. NEXT_DAY(SYSDATE, 'SATURDAY') or NEXT_DAY(SYSDATE, 'SUNDAY') etc.
Currently I will use the following work, but I would really like to know why NEXT_DAY() behaves differently in PL / SQL than in SQL.
DECLARE dteExpires DATE; BEGIN -- 2017-01-01 = SUNDAY dteExpires := NEXT_DAY(SYSDATE, TO_CHAR(TO_DATE('2017-01-01', 'YYYY-MM-DD'), 'DAY')); END;
This is my dev environment:
SELECT * FROM v$version;
BANNER -------------------------------------------------------------------------------- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production PL/SQL Release 12.1.0.2.0 - Production CORE 12.1.0.2.0 Production TNS for 64-bit Windows: Version 12.1.0.2.0 - Production NLSRTL Version 12.1.0.2.0 - Production 5 rows selected.
source share