Mysql is a method that updates part of the data in a field in both cases

  • 2020-05-17 06:47:09
  • OfStack

Mysql updates partial data in field 1:

update tab set A = concat(substring(A,1,3),'bbb');


Take 3 characters from 1 character of A, add 'bbb', and then write to a. If the original value of A is '123aaa', then the updated value is '123bbb'.

What if we were to replace the 1 contained in the A value with the 2?
For example, a=2211, and now I'm going to replace it with 2222, so I'm going to replace 1 with 2
The SQl statement reads:

update table set a=REPLACE(a,'1','2');

Related articles: