我们如何在单个sql (mysql)查询中实现这一点?
我需要在一列中搜索一些模式,如果有任何模式匹配,则将该模式替换为特定字符串。就像如果
pattern ptr1 matches then replace this with str1
pattern ptr2 matches then replace this with str2我需要一个像replace这样的函数来替换正则表达式。以下是我的查询,我需要对正则表达式进行改进
UPDATE category SET column1 =
(
CASE
WHEN (column1 REGEXP 'xy') THEN REPLACE(column1, 'xy' , 'ffff')
ELSE column1
END
)在这方面请帮帮我。
发布于 2013-06-03 15:48:54
您可以在更新表值时放入多个替换函数-
UPDATE category SET column1 =
REPLACE(REPLACE(column1,
ptr1,
str1),
ptr2,
str2)https://stackoverflow.com/questions/16891972
复制相似问题