SQL 查询帮助 - where 子句中的字符串具有 & 字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5020709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Query Help - String in where clause has & character
提问by x.509
I am running an SQL (Oracle) statement like that
我正在运行这样的 SQL (Oracle) 语句
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.
在运行 TOAD 时,它会将&视为某个变量占位符并询问其值。如果是 1-2 个占位符,那么我可以在 TOAD 中设置它,但是 in 子句有 200 个字符串。
How to put this query?
如何提出这个查询?
I want to export the DATASET as SQL INSERT statement, so I can't use this in SQL-PLUS.
我想将 DATASET 导出为 SQL INSERT 语句,所以我不能在 SQL-PLUS 中使用它。
采纳答案by Michael Broughton
In TOAD, you can disable the prompt for substitution variables from the options dialog:
在 TOAD 中,您可以从选项对话框中禁用替换变量的提示:
You need to uncheck: View –> Toad Options –> Execute/Compile –> Prompt for Substitution variables.
您需要取消选中:View –> Toad Options –> Execute/Compile –> Prompt for Substitution variables。
回答by Randy
SET DEFINE OFF;
Will work to turn the prompting for variable off..
将工作关闭提示变量..
or
或者
SET ESCAPE ON;
SELECT 'blah \& blah' AS DES FROM DUAL;
回答by Tommi
You can escape the ampersand character by using concatenation, like this:
您可以使用连接来转义 & 字符,如下所示:
select * from table
where table_id in ('265' || '&' || '310', '266' || '&' || '320')