I need to replace all double quotes to single quotes using mysql query.
How can I do that. My sql should be in double quotes.
mysql="select replace(text,'\"',''') from mytable"
throwing error. How can I escape that single quotes inside query?
Backspace over the double quotes and then type a single quote.
Use the String. replaceAll() method to replace single with double quotes, e.g. const replaced = str. replaceAll("'", '"'); . The replaceAll method will return a new string where all occurrences of single quotes are replaced with double quotes.
If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.
Try this one
$mysql="select replace(text,'\"',\"'\") from mytable";
Then the query will become
select replace(text,'"',"'") from mytable
at the Mysql end.
You need to escape the single quote '
too (see table 8.1):
mysql="select replace(text,'\"','\\'') from mytable"
Thus, the string sent to MySQL will read:
select replace(text,'"','\'') from mytable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With