在phpMyAdmin中使用REPLACE和转义字符

时间:2022-03-13 20:25:46

I have a database of information that was submitted from a website. The main column data was entered using Markdown, and contains lots of text that looks like this:

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

Walgreens (www.walgreens.com) is the nation\\\'s largest drugstore chain.

We're switching over to a different wysiwyg editor, and need to clean up the data. I tried doing this in phpMyAdmin:

我们正在切换到不同的所见即所得编辑器,需要清理数据。我试过在phpMyAdmin中这样做:

UPDATE sc_answer
SET answer_text = REPLACE (answer_text, '\\\', '')
WHERE sc_answer_id = 24806

but I get an error:

但是我收到一个错误:

#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

Can anyone help me out? What do I need to do to get this to work?

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

1 个解决方案

#1


4  

For each backslash \ in the text field, use 2 backslashes in the SQL. For example, if your table looks like this:

对于文本字段中的每个反斜杠\,在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)

then

然后

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)

#1


4  

For each backslash \ in the text field, use 2 backslashes in the SQL. For example, if your table looks like this:

对于文本字段中的每个反斜杠\,在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)

then

然后

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)

相关文章