如何在 Oracle 中转义单引号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28906354/
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
How to escape single quotes in Oracle?
提问by Kevin
I have a column containing certain expressions stored as a text string which include single quotatons, such as 'missed transaction' (INCLUDING the quotations)
我有一列包含存储为文本字符串的某些表达式,其中包括单个配额,例如“错过的交易”(包括引号)
How can I use a where clause with such an occurance?
我怎样才能在这种情况下使用 where 子句?
select * from table where reason = ''missed transaction''
select * from table where reason = ''missed transaction''
doesn't work, and I can't use the replace function because it also requires single quotations in its syntax. Obscure problem, i know. But thanks for any help.
不起作用,我不能使用替换函数,因为它的语法也需要单引号。晦涩的问题,我知道。但感谢您的任何帮助。
回答by Jean-Fran?ois Savard
You need to escape the '
by doubling them :
您需要'
通过将它们加倍来逃避:
select * from table where reason = '''missed transaction''';
回答by Jeffrey Kemp
The q
quote syntax makes this sort of thing easier:
该q
报价语法使得这种容易的事情:
select * from table where reason = q'['missed transaction']'
Everything between the '[
and the ]'
is interpreted literally, so no need to double all the quotes, however many there may be.
'[
和之间的所有内容都按]'
字面解释,因此无需将所有引号都加倍,无论有多少。