Use of MYSQL batch substitution replace syntax


In the actual demand, the contents in a certain table and a certain field need to be replaced in batches. The common thinking process is as follows: SELECT out str_replace replacement UPDATE write In fact, this is extremely wasteful and consumes resources. MYSQL has a batch substitution syntax built in

UPDATE table SET field = replace(field,' Be replaced ',' replace '

I’m just going to do it, and I can also do it with WHERE Support for multiple word substitutions at the same time

UPDATE table SET field = replace(field,' Be replaced 1',' replace 1'),field = replace(field,' Be replaced 2',' replace 2'

Very powerful, the latter 1 time sex change many is not on the net the column son, now record down