MySQL 如何使用mysql替换将所有双引号替换为单引号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8182291/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:45:29  来源:igfitidea点击:

How to replace all double quotes to single quotes using mysql replace?

mysqlsqlescapingquotesmysql5

提问by DEVOPS

I need to replace all double quotes to single quotes using mysql query.

我需要使用 mysql 查询将所有双引号替换为单引号。

How can I do that. My sql should be in double quotes.

我怎样才能做到这一点。我的 sql 应该是双引号。

mysql="select replace(text,'\"',''') from mytable"

throwing error. How can I escape that single quotes inside query?

抛出错误。如何在查询中转义单引号?

回答by Shakti Singh

Try this one

试试这个

 $mysql="select replace(text,'\"',\"'\") from mytable";

Then the query will become

然后查询将变成

select replace(text,'"',"'") from mytable

at the Mysql end.

在 Mysql 端。

回答by jensgram

You need to escape the single quote 'too (see table 8.1):

你也需要转义单引号'见表 8.1):

mysql="select replace(text,'\"','\'') from mytable"

Thus, the string sent to MySQL will read:

因此,发送到 MySQL 的字符串将显示为:

select replace(text,'"','\'') from mytable