【问题标题】:Using REPLACE with escape characters in phpMyAdmin在 phpMyAdmin 中使用带有转义字符的 REPLACE
【发布时间】:2012-02-19 17:45:02
【问题描述】:

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

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

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

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

但我得到一个错误:

#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

谁能帮帮我?我需要做什么才能让它工作?

【问题讨论】:

    标签: mysql phpmyadmin


    【解决方案1】:

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

    然后

    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)
    

    【讨论】:

      猜你喜欢
      • 2013-12-27
      • 2011-09-09
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2021-11-21
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多