开发者

MySQL update Loop -> how to

开发者 https://www.devze.com 2023-03-22 10:52 出处:网络
I want to loop the following command, for all distinct values in a column upd开发者_StackOverflow中文版ate myTable set myUglyField = replace(myUglyField,\'<trimmed distinct value here>\\r\\n\',

I want to loop the following command, for all distinct values in a column

upd开发者_StackOverflow中文版ate myTable set myUglyField = replace(myUglyField,'<trimmed distinct value here>\r\n','<trimmed distinc value here>');

Anyone know if this could be done, instead of going one by one to remove \r\n


If you run that query you have right there it will update ALL rows in the table, so I think you're good.


Suppose you have all replacements in a table (3 columns, in which value, what to replace and the replacement), you can write:

update myTable join replacements on myTable.myUglyFied = replacements.in_value
set myUglyField = replace(myUglyField, replacements.what_to_replace, replacements.replacement)
0

精彩评论

暂无评论...
验证码 换一张
取 消