Need help in incrementing the date in oracle

dateoracleselect

Error thrown as "Invalid number" while trying to increment the date. Given below is the query executed through sqlplus. Please help me on this.

select ''''||to_date(:To_date, 'dd-mon-yyyy')+1||'''' from DUAL;

Expected output (if :To_date variable is '09-DEC-2014'):

'10-DEC-2014'

Best Answer

Note the extra brackets.

SQL> variable d varchar2(100);
SQL> exec :d := '09-DEC-2014';

PL/SQL procedure successfully completed.

SQL> select '''' || (to_date(:d, 'DD-MON-YYYY') + 1) || '''' from dual;

''''||(TO_DATE(:D,'D
--------------------
'10-DEC-14'

Changing date format:

SQL> alter session set nls_date_format='DD-MON-YYYY';

Session altered.

SQL> select '''' || (to_date(:d, 'DD-MON-YYYY') + 1) || '''' from dual;

''''||(TO_DATE(:D,'DD-
----------------------
'10-DEC-2014'