开发者

How to replace single-quote with double-quote in sql query - oracle 10g?

开发者 https://www.devze.com 2022-12-09 01:17 出处:网络
How can I replace single-quote (\') with double-quote (\") in sql query - oracle开发者_运维知识库 10g?This should work:

How can I replace single-quote (') with double-quote (") in sql query - oracle开发者_运维知识库 10g?


This should work:

UPDATE myTable
SET myField = REPLACE(myField, '''', '"');


You can use Ansi-codes as well, to make it more crystal what is happening:

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


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 "


This should work:

UPDATE myTable
SET field = replace(your_string,Chr(39),Chr(39)||Chr(39));


Ten bucks says this thing is wide-open to SQL injection and the correct answer is to use parameterization.

0

精彩评论

暂无评论...
验证码 换一张
取 消