As part of a script that I run, I spool to a log file. The name of the log file includes a literal value entered
by the user. In some cases, this literal value must include a single quote (aka an apostrophe), as in the case
of a last name like O'DOWD. In these cases, I need to include an additional single quote.
Here's part of the script:
ACCEPT for_user PROMPT 'Enter user ID: '
COLUMN dummy NEW_VALUE v_spool_name
SELECT 'LOG_'||UPPER('&for_user')||'_'||
TO_CHAR(SYSDATE, 'dd-MON-yyyy')||'.sql' dummy
FROM dual;
SPOOL c:\logs\&&v_spool_name
The following error is raised when the value JOHN.O'DOWD is entered:
ORA-01756: quoted string not properly terminated
The easiest solution is to enter 2 single quote when prompted (i.e., JOHN.O''DOWD).
But, if possible, I would like to use some logic to check the entry for the inclusion of a single quote and when the entered value includes a single quote, replace it with two single quotes. Is this possible within a select statement such as this? (There are subsequent uses of the entered value in the script using the same select method.)
Thanks for any help!
by the user. In some cases, this literal value must include a single quote (aka an apostrophe), as in the case
of a last name like O'DOWD. In these cases, I need to include an additional single quote.
Here's part of the script:
ACCEPT for_user PROMPT 'Enter user ID: '
COLUMN dummy NEW_VALUE v_spool_name
SELECT 'LOG_'||UPPER('&for_user')||'_'||
TO_CHAR(SYSDATE, 'dd-MON-yyyy')||'.sql' dummy
FROM dual;
SPOOL c:\logs\&&v_spool_name
The following error is raised when the value JOHN.O'DOWD is entered:
ORA-01756: quoted string not properly terminated
The easiest solution is to enter 2 single quote when prompted (i.e., JOHN.O''DOWD).
But, if possible, I would like to use some logic to check the entry for the inclusion of a single quote and when the entered value includes a single quote, replace it with two single quotes. Is this possible within a select statement such as this? (There are subsequent uses of the entered value in the script using the same select method.)
Thanks for any help!