Oracle SQLPlus – How to Use ACCEPT Command

oraclesqlplus

I want to ask in SQL script for a start and finish date with accept but I get an error.

accept v_FechaInicio date format 'DD/MM/YYYY-HH24:MI:SS' prompt 'Fecha de inicio ('DD/MM/YYYY-HH24:MI:SS'): '
accept v_FechaFin date    format 'DD/MM/YYYY-HH24:MI:SS' prompt 'Fecha de fin    ('DD/MM/YYYY-HH24:MI:SS'):'

SQL> SQL> SQL> SP2-0003: Ill-formed ACCEPT command starting as DD/MM/YYYY-HH24:MI:SS'): '
SQL> SP2-0003: Ill-formed ACCEPT command starting as DD/MM/YYYY-HH24:MI:SS'):'
SQL> accept v_FechaInicio date format 'DD/MM/YYYY-HH24:MI:SS' prompt 'Fecha de inicio ('DD/MM/YYYY-HH24:MI:SS'): '
SP2-0003: Ill-formed ACCEPT command starting as DD/MM/YYYY-HH24:MI:SS'): '

What is the problem?

Best Answer

It looks like your ACCEPT prompt includes quotation marks. But quotation marks are also used to delimit the prompt string, so if you want to include those characters into the prompt, you need to double them:

… prompt 'Fecha de inicio (''DD/MM/YYYY-HH24:MI:SS''): '
… prompt 'Fecha de fin    (''DD/MM/YYYY-HH24:MI:SS''):'

Although I think you could simply omit them, since this is just a prompt:

… prompt 'Fecha de inicio (DD/MM/YYYY-HH24:MI:SS): '
… prompt 'Fecha de fin    (DD/MM/YYYY-HH24:MI:SS): '