duankeye2342 2016-06-23 09:30
浏览 29
已采纳

如何更新MySql表中编码错误的字符?

In an existing database, we have discovered some text entries where characters with accents were badly encoded.

The following query:

SELECT 
    PR.Product_Ref__ AS ProductCode,
    CONCAT(P.Name, IF (PR.Misc <> '', CONCAT(' ', PR.Misc), '')) AS Name
FROM
    Product AS P
        INNER JOIN
    Product_Ref AS PR ON P.Product__ = PR.Product__
WHERE
    Name like "%é%" AND
    PR.Product_Ref__ IN ( 659491, 657274 )

returns two lines describing the issue:

enter image description here

Sometimes, e with accent has been inserted properly, sometimes not.

How can I detect and update such issue with an UPDATE ... WHERE ...? Or should I use a different statement/method?

P.S.: The corresponding application is developed in PHP.

P.S.2: The answers in the suggested possible duplicate question do not address the issue I am raising. It is not related to the collation of the database.

  • 写回答

1条回答 默认 最新

  • doutu9810 2016-06-23 09:43
    关注

    You just can simple detect all the occurrences that you want to correct and the use a simple update clause to make the substitutions.

    Example for the case that you describe:

    UPDATE Product
    SET Name = REPLACE(Name, 'é', 'é')
    WHERE Name like '%é%'
    

    You can run this updates directly in mysql databases, using the command line or in a specific mysql user interface client application. Or if you like, using php functions that run sql statements in the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路