在phpMyAdmin中使用带有转义字符的REPLACE

Emm*_*myS 5 mysql phpmyadmin

我有一个从网站提交的信息数据库.主列数据是使用Markdown输入的,包含许多如下所示的文本:

Walgreens (www.walgreens.com) is the nation\\\'s largest drugstore chain.
Run Code Online (Sandbox Code Playgroud)

我们正在切换到另一个所见即所得的编辑器,需要清理数据.我尝试在phpMyAdmin中执行此操作:

UPDATE sc_answer
SET answer_text = REPLACE (answer_text, '\\\', '')
WHERE sc_answer_id = 24806
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\\\', '') WHERE sc_answer_id = 24806' at line 3
Run Code Online (Sandbox Code Playgroud)

谁能帮我吗?我需要做些什么才能让它发挥作用?

unu*_*tbu 4

对于\文本字段中的每个反斜杠,在 SQL 中使用 2 个反斜杠。例如,如果您的表如下所示:

mysql> select * from foo;
+----+---------------------------------------------------------------------------+
| id | bar                                                                       |
+----+---------------------------------------------------------------------------+
|  1 | Walgreens (www.walgreens.com) is the nation\\\'s largest drugstore chain. |
+----+---------------------------------------------------------------------------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

然后

mysql> update foo set bar = REPLACE(bar,'\\\\\\','') where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from foo;
+----+------------------------------------------------------------------------+
| id | bar                                                                    |
+----+------------------------------------------------------------------------+
|  1 | Walgreens (www.walgreens.com) is the nation's largest drugstore chain. |
+----+------------------------------------------------------------------------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)