[英]mysql update column values with replace
one of my table contains column path stores the URL example:\\xyz\\attachments, \\abc\\attachments, etc total i have 16 combinations to replace 我的表格之一包含存储URL的列路径示例:\\ xyz \\ attachments,\\ abc \\ attachments等,总共有16种组合需要替换
i found rows by using rlike in where clause 'abc|xyz|' 我在where子句“ abc | xyz |”中使用rlike找到行
have to update xyz with xxx or abc with yyyy 必须使用xxx更新xyz或使用yyyy更新abc
i am not sure how to update these part of the values of column. 我不确定如何更新列值的这些部分。 Is it possible using single query or i have to write 16 queries to do that? 是否可以使用单个查询或我必须编写16个查询来做到这一点? please advise here 请在这里建议
This is not reliable, but is doable. 这是不可靠的,但是可行的。 Basically nested replace()
calls: 基本上嵌套的replace()
调用:
UPDATE ...
SET yourfield = REPLACE(REPLACE(yourfield, '\\xyz', 'newtext'), '\\abc', 'othertext')
Note that if xyz
or abc
can appear in multiple places in either string, you may end up replacing something that shouldn't have been. 请注意,如果xyz
或abc
可以出现在任一字符串的多个位置,则您可能最终替换了不应该使用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.