SQL 如何在sql查询-oracle 10g中用双引号替换单引号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1589236/
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 replace single-quote with double-quote in sql query - oracle 10g?
提问by Gold
How can I replace single-quote (') with double-quote (") in sql query - oracle 10g?
如何在 sql 查询中用双引号 (") 替换单引号 (') - oracle 10g?
回答by Kip
This should work:
这应该有效:
UPDATE myTable
SET myField = REPLACE(myField, '''', '"');
回答by Robert Giesecke
You can use Ansi-codes as well, to make it more crystal what is happening:
您也可以使用 Ansi 代码,以使其更加清晰:
SELECT someString
,replace(someString, Chr(39), Chr(34)) as replacedString
FROM (SELECT ' abc ' || Chr(39) || ' def ' as someString
FROM Dual)
39 is a single quote, 34 a double quote
39是单引号,34是双引号
回答by Gavin
If you have a variable in single quotes with an apostrophe e.g. 'John's Book', simply insert 2 apostrophes. i.e. 'John''s Book'. NOTE: Do NOT use a double quotation "
如果您在单引号中有一个带有撇号的变量,例如“John's Book”,只需插入 2 个撇号。即“约翰的书”。注意:不要使用双引号“
回答by NEERAJ MISHRA
This should work:
这应该有效:
UPDATE myTable
SET field = replace(your_string,Chr(39),Chr(39)||Chr(39));
回答by Mark Sowul
Ten bucks says this thing is wide-open to SQL injection and the correct answer is to use parameterization.
十块钱说这个东西对 SQL 注入是开放的,正确的答案是使用参数化。