Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL escape character (for a '&')

While attempting to execute SQL insert statements using Oracle SQL Developer I keep generating an "Enter substitution value" prompt:

insert into agregadores_agregadores  (  idagregador,  nombre,  url )  values  (  2,  'Netvibes',  'http://www.netvibes.com/subscribe.php?type=rss\&url=' ); 

I've tried escaping the special character in the query using the '\' above but I still can't avoid the ampersand, '&', causing a string substitution.

like image 966
ian_scho Avatar asked Jul 16 '09 12:07

ian_scho


People also ask

How do I escape a special character in Oracle SQL?

Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence. When you use braces to escape a single character, the escaped character becomes a separate token in the query. Use the backslash character to escape a single character or symbol.

How do I add a special character to a table in Oracle?

There are 3 ways to do so : 1) Simply do SET DEFINE OFF; and then execute the insert stmt. 2) Simply by concatenating reserved word within single quotes and concatenating it. E.g. Select 'Java_22 ' || '& '|| ':' || ' Oracle_14' from dual --(:) is an optional.

How do I escape a keyword in Oracle?

Querying Escape Characters Everything between the opening brace and the closing brace is part of the escaped query expression (including any open brace characters). To include the close brace character in an escaped query expression, use }} . To escape the backslash escape character, use \\ .

How do I allow special characters in Oracle?

Oracle recommends that you enclose parameter and value pairs in double quotation marks. These special characters must be escaped using double quotation marks (") around the special character or around the parameter value containing the special character.


2 Answers

the & is the default value for DEFINE, which allows you to use substitution variables. I like to turn it off using

SET DEFINE OFF 

then you won't have to worry about escaping or CHR(38).

like image 176
Neil Kodner Avatar answered Oct 21 '22 07:10

Neil Kodner


|| chr(38) ||

This solution is perfect.

like image 30
Aseem Avatar answered Oct 21 '22 07:10

Aseem