此 UGLY 查询适用于字符串中最多 4 次替换。如果您需要更多替换,最好的方法是创建一个用户定义函数来替换一个字符串中的这些单词并使用它进行更新。
UPDATE table1 a
LEFT JOIN lookup b1 on a.username LIKE CONCAT('%', b1.`WRONG`, '%')
LEFT JOIN lookup b2 on a.username LIKE CONCAT('%', b2.`WRONG`, '%')
and (b2.Wrong not in (b1.Wrong))
LEFT JOIN lookup b3 on a.username LIKE CONCAT('%', b3.`WRONG`, '%')
and (b3.Wrong not in (b1.Wrong,b2.Wrong))
LEFT JOIN lookup b4 on a.username LIKE CONCAT('%', b4.`WRONG`, '%')
and (b4.Wrong not in (b1.Wrong,b2.Wrong,b3.Wrong))
SET a.username =
REPLACE(
REPLACE(
REPLACE(
REPLACE(a.username, IFNULL(b1.`WRONG`,''), IFNULL(b1.`RIGHT`,''))
, IFNULL(b2.`WRONG`,''), IFNULL(b2.`RIGHT`,''))
, IFNULL(b3.`WRONG`,''), IFNULL(b3.`RIGHT`,''))
, IFNULL(b4.`WRONG`,''), IFNULL(b4.`RIGHT`,''))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
104 次 |
| 最近记录: |