当前位置:网站首页>How does MySQL control the number of replace?

How does MySQL control the number of replace?

2022-07-07 13:51:00 Full stack programmer webmaster

I want to put “ABC yes ABC” Replace with “123 yes ABC”, That is to find the first one ABC Replace with 123,MYSQL How the order should be written ?

UPDATE data SET body=REPLACE(body, ‘ABC’, ‘123’); When I use this command, I will put all ABC Are replaced with 123, I don't know how to control the number of replacements , Ask an expert for advice .

hemu780924 Brother's code can be used , But there is a fatal flaw ,

 such as "123 yes ABC", If you want to find XYZ And replace it with OPQ, Because in "123 yes ABC" Can't find XYZ, Then the order will be "123 yes ABC" Insert in front XYZ, This is not what I want !
update table1 set body = 
concat(
       SUBSTRING(body ,1,position('ABC' in body )-1),
       '123',
       substring(body ,position('ABC' in body )+length('ABC')))  where body like '%ABC%'
 Here replace the first ABC , No, ABC No replacement 

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113283.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071146402879.html