mysql replace a character in a field

A field of a table in Msql stores a person's address, and one day a certain place in this address

If his name changes, his address will also change:

for example:

It turned out to be:

table name: user_item, field: addr  

 

 

 

 

 

[html]  view plain copy  
 
  1. number             addr  
  2. 01 No. 05, XXXXXX Street, Chengdu City, Sichuan Province  
  3. 02 No. 07, XXXXXX Street, Chengdu City, Sichuan Province  
  4. 03 No. 09, XXXXXX Street, Chengdu City, Sichuan Province  
  5. 04 No. 04, XXXXXX Street, Chengdu City, Sichuan Province  

 Now the city of Chengdu has become a "Tianfu" city...

 

Therefore, all the values ​​in the addr field should be changed from Chengdu to Tianfu

 

Solution:

sql statement:

[sql]  view plain copy  
 
  1. update table name set field name=REPLACE (field name, 'original value', 'value to be modified')    

Of course, you can also add conditions:

 

[sql]  view plain copy  
 
  1. update user_item set addr=REPLACE (addr,'成都','天府') where time<'2013-11--5'    
  2. <strong><span style="color:#FF6666;">UPDATE `dqca02` SET `qt` = REPLACE (qt,'?aaaa','aaaa')//The table is dqca02, the field is qt, and the content is "?aaaa", all changed to "aaaa"</span></strong>  

The final effect:

 

 

[sql]  view plain copy  
 
  1. number             addr    
  2. 01 No. 05, XXXXXX Street, Tianfu City, Sichuan Province    
  3. 02 No. 07, XXXXXX Street, Tianfu City, Sichuan Province    
  4. 03 No. 09, XXXXXX Street, Tianfu City, Sichuan Province    
  5. 04 No. 04, XXXXXX Street, Tianfu City, Sichuan Province    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325297129&siteId=291194637