Query Help - String in where clause has & character

試著忘記壹切 提交于 2020-01-11 03:10:07

问题


I am running an SQL (Oracle) statement like that

select * from table 
where table_id in ('265&310', '266&320')

While running through TOAD, it consider & as some variable placeholder and it asks for its value. If it was for 1-2 place holders then I could have set it in TOAD but the in clause has like 200 of strings.

How to put this query?

I want to export the DATASET as SQL INSERT statement, so I can't use this in SQL-PLUS.


回答1:


In TOAD, you can disable the prompt for substitution variables from the options dialog:

You need to uncheck: View –> Toad Options –> Execute/Compile –> Prompt for Substitution variables.




回答2:


SET DEFINE OFF;

Will work to turn the prompting for variable off..

or

SET ESCAPE ON;
SELECT 'blah \& blah' AS DES FROM DUAL;



回答3:


You can escape the ampersand character by using concatenation, like this:

select * from table 
where table_id in ('265' || '&' || '310', '266' || '&' || '320')


来源:https://stackoverflow.com/questions/5020709/query-help-string-in-where-clause-has-character

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