mysql 替换函数字符串

此文章发布于21个月前,部分信息可能已经过时,请自行斟酌确认

使用replace函数替换mysql数据库中某字段的特定字符串

代码示例:


#示例
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 需要替换的字符串
  • from_str 替换成的字符串

真实项目示例:

需求:将userimgurl字段中所有的http://7.310.82.93更改为http://7.310.82.93:6087.


update `user` set `imgurl` = replace(imgurl, 'http://7.310.82.93', 'http://7.310.82.93:6087') where `imgurl` like '%http://7.310.82.93%';

PS:该函数是多字节安全的,也就是说你不用考虑是中文字符还是英文字符.

参考链接:https://blog.csdn.net/qq_36663951/article/details/78791138

最后修改:2021 年 09 月 06 日 01 : 24 PM
如果觉得我的文章对你有用,请随意赞赏

此处评论已关闭