The following doesn't work:
set ServerOutput ON
accept anyDate DATE FORMAT 'YYYY-MM-DD' default '1982-01-24' prompt "Enter a date in this format 'YYYY-MM-DD':"
DECLARE
BEGIN
dbms_output.put_line(TO_CHAR(&anyDate, 'DD MONTH YYYY'));
END;
The following doesn't work:
set ServerOutput ON
accept anyDate DATE FORMAT 'YYYY-MM-DD' default '1982-01-24' prompt "Enter a date in this format 'YYYY-MM-DD':"
DECLARE
BEGIN
dbms_output.put_line(TO_CHAR(&anyDate, 'DD MONTH YYYY'));
END;
Because &anyDate
will expand to a string you have to quote it:
TO_CHAR('&anyDate', 'DD MONTH YYYY')
See SQL*Plus how to accept text variable from prompt? for the details.
Here is an example that also addresses the conversion:
SQL@xe> accept foo date format 'YYYY-MM-DD' default '2000-01-01' prompt 'enter date: '
enter date: 2014-12-13
SQL@xe> select to_char(to_date('&foo', 'YYYY-MM-DD'), 'DD MONTH YYYY' ) from dual;
old 1: select to_char(to_date('&foo', 'YYYY-MM-DD'), 'DD MONTH YYYY' ) from dual
new 1: select to_char(to_date('2014-12-13', 'YYYY-MM-DD'), 'DD MONTH YYYY' ) from dual
TO_CHAR(TO_DATE('
-----------------
13 DECEMBER 2014
SQL@xe>
I CAN SUGGEST A DIFFERENT WAY.Instead of using accept and prompt you can try this snippet it may resolve your problem.
SET ServerOutput ON
--Accept anyDate DATE FORMAT 'YYYY-MM-DD' default '1982-01-24' prompt "Enter a date in this format 'YYYY-MM-DD':"
DECLARE
DT_VAR VARCHAR2(100);
anydate DATE;
BEGIN
dt_var :='&Enter_date';
anydate:=TO_DATE(dt_var,'YYYY-MM-DD');
DT_VAR :=TO_CHAR(anydate,'MONTH');
dbms_output.put_line(DT_VAR);
END;
Hi you can use something like this -
Select DateName( month , DateAdd( month , @MonthNumber , -1 ) )