Oracle SQL escape character (for a '&')

SqlOracleEscapingOracle Sqldeveloper

Sql Problem Overview


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.

Sql Solutions


Solution 1 - Sql

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).

Solution 2 - Sql

|| chr(38) ||

This solution is perfect.

Solution 3 - Sql

Set the define character to something other than &

SET DEFINE ~
create table blah (x varchar(20));
insert into blah (x) values ('blah&amp');
select * from blah;

X

blah&amp

Solution 4 - Sql

insert into AGREGADORES_AGREGADORES (IDAGREGADOR,NOMBRE,URL)
values (2,'Netvibes',
'http://www.netvibes.com/subscribe.php?type=rss' || chr(38) || 'amp;url=');

Solution 5 - Sql

SELECT 'Free &' || ' Clear' FROM DUAL;

Solution 6 - Sql

select 'one'||'&'||'two' from dual

Solution 7 - Sql

The real answer is you need to set the escape character to '': SET ESCAPE ON

The problem may have occurred either because escaping was disabled, or the escape character was set to something other than ''. The above statement will enable escaping and set it to ''.


None of the other answers previously posted actually answer the original question. They all work around the problem but don't resolve it.

Solution 8 - Sql

add this before your request

set define off;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionian_schoView Question on Stackoverflow
Solution 1 - SqlNeil KodnerView Answer on Stackoverflow
Solution 2 - SqlAseemView Answer on Stackoverflow
Solution 3 - SqlRC.View Answer on Stackoverflow
Solution 4 - SqlJeffrey KempView Answer on Stackoverflow
Solution 5 - SqldrjView Answer on Stackoverflow
Solution 6 - SqlIzoView Answer on Stackoverflow
Solution 7 - SqlTerrible TadpoleView Answer on Stackoverflow
Solution 8 - SqlHelaliView Answer on Stackoverflow