在 MySQL 表中查找和替换转义引号 [英] To find and replace escaped quotes in MySQL table
问题描述
我的数据库有内容之前已经被转义,导致字符串如
My database has content that has been previously escaped, resulting in string such as
此值为无效".
我想去掉转义字符 \
但我很难找到这些行.我的第一次尝试
I want to get rid of escape character \
but I'm having a hard time to find these rows. My first attempt
select value from content where value like '%\\"%';
未能将 \"
与 "
分开,并返回有效行,例如
fails to separate \"
from "
, and returns valid rows such as
这个值是有效的".
那么我怎样才能查询字符串 \"
,最好以一种可以在更新子句中使用以删除斜杠的方式?
So how can I query for the string \"
, preferably in a way than can be used in an update clause to remove the slash?
这里的 SQL Fiddle http://sqlfiddle.com/#!9/fc3d3/6请注意,第 3 行的查询返回两行.
SQL Fiddle here http://sqlfiddle.com/#!9/fc3d3/6 Notice that the query at line 3 returns both rows.
推荐答案
我已经检查了你的 sqlfiddle.
I've checked your sqlfiddle.
这会得到无效的行:
SELECT * from myTable where content<>REPLACE(content,'\\\"','\"')
如果可行,那么您只需将 content
列更新为 REPLACE(content,'\\\"','\"')
.
If this works, then you can simply update your content
column to REPLACE(content,'\\\"','\"')
.
这篇关于在 MySQL 表中查找和替换转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!