mysql批量替换某个字段内容

背景

现在有如下数据,实际数据有成百上千条,想将【队伍名1】替换成【队伍1】,一条条替换直接气死个人。
在这里插入图片描述

方法

首先想到的自然是像代码替换或者正则那样的方法。

mysql有个REPLACE(str,old_string,new_string)方法str 为字段名,可以直接替换字段中旧值为新值。
REPLACE详细说明

update table b
set b.content = replace(b.content, '【队伍名1】', '【队伍1】')
where b.content like '%【队伍名1】%';

一条sql搞定。

猜你喜欢

转载自blog.csdn.net/weixin_46080554/article/details/127959832