Oracle SQL escape character (for a '&')

谁说我不能喝 提交于 2019-11-26 08:19:39

问题


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.


回答1:


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




回答2:


|| chr(38) ||

This solution is perfect.




回答3:


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 




回答4:


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



回答5:


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



回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/1137354/oracle-sql-escape-character-for-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!