Home » SQL & PL/SQL » SQL & PL/SQL » Escaping Single Quotes in dynamic SQL
Escaping Single Quotes in dynamic SQL [message #15604] |
Fri, 15 October 2004 10:20  |
Randy White
Messages: 2 Registered: October 2004
|
Junior Member |
|
|
�
�Hi,
�We use dynamic SQL to create insert statements.
�Obviously, it breaks when the inserted value contains a single quote (').� Could one of the experts help us out with the best way to get around this.
�Thanks
�Rand
�
�
�
�
|
|
|
|
|
|
|
Re: Escaping Single Quotes in dynamic SQL [message #15619 is a reply to message #15610] |
Sat, 16 October 2004 06:53   |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
Assuming the dynamic code is necessary, you can just use REPLACE to double up all the quotation marks, i.e:
REPLACE(v_txt,'''','''''')
or if you prefer,
REPLACE(v_txt, CHR(39), CHR(39)||CHR(39))
or even
k_quote CONSTANT VARCHAR2(1) := CHR(39);
...
REPLACE(v_txt, k_quote, k_quote||k_quote)
this will change (for example) O'Reilly into O''Reilly.
|
|
|
|
Goto Forum:
Current Time: Thu Jun 05 01:59:07 CDT 2025
|