简体   繁体   中英

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

i found rows by using rlike in where clause 'abc|xyz|'

have to update xyz with xxx or abc with yyyy

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? please advise here

This is not reliable, but is doable. Basically nested replace() calls:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM