sql批量修改字段前缀后缀
1.增加前缀或后缀:
可以使用concat(str1,str2,…)函数。用法如下:
1.增加前缀:
update table set name = concat('prefix_',name);
2.增加后缀:
update table set name = concat(name,'_suffix');
3.同时加前缀以及后缀:
update table set name = concat('prefix_',name,'_suffix');
2.去掉前缀或者后缀:
去掉前缀:
可以使用substr()函数(substring)或者replace()函数
substr(str,pos):
str:要截取的字符串;pos:截取开始位置,从1开始。用法如下:
update table set name = SUBSTR(name,8) ;
去掉后缀:
可以使用 substring_index(str,delim,count):delim:限定符;count:第几次;
以下为取第一次出现’_suffix’之前的所有字符,如果没找到限定符,则返回整个str。
update table set name = SUBSTRING_INDEX(name,'_suffix',1);
replace()函数可以去掉前缀或后缀:
REPLACE(str,from_str,to_str):
str:要替换的字符串;from_str:要替换的字段;to_str:替换成的字段;
用法如下:
update table set name = REPLACE(name,'prefix_','')
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
· 全程使用 AI 从 0 到 1 写了个小工具