14

How can I replace single-quote (') with double-quote (") in sql query - oracle 10g?

5 Answers 5

23

This should work:

UPDATE myTable
SET myField = REPLACE(myField, '''', '"');
Sign up to request clarification or add additional context in comments.

Comments

9

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

Comments

0

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 "

Comments

0

This should work:

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

1 Comment

I believe your answer is replacing a ' with two duplicate characters (''). While it might looks the same, it's actually not the same character as the author asked about, which is " (character 34).
-3

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

2 Comments

This answer would have been much more helpful if you'd provided an example of parameterization. How would you use it to solve this problem?
We know nothing about the environment from which this is being called, nor the query, so there's no general example I can give that will be in any way relevant. It's probably something called from client code and there are any number of ways to parameterize that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.