mysql 替换函数replace()实现mysql替换指定字段中的字符串

mysql 替换字符串的实现方法:

mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便。 mysql 替换函数replace()

 

UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'

 

说明:

table_name —— 表的名字

field_name —— 字段名

from_str —— 需要替换的字符串

to_str —— 替换成的字符串


比如你要将表 tb1里面的 f1字段的abc替换为def 
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); 

 

update cy_ct_game_activity set title=REPLACE(title,'B游汇','异酷游') where title like "%B游汇%"
update cy_ct_game_activity set content=REPLACE(content,'B游汇','异酷游') where content like "%B游汇%"

Copyright Liukaiweb.Com Rights Reserved.

 渝ICP备2021008408号-5