添加前、后缀 concat,字符串替换 replace
添加前缀
UPDATE `table` SET field_name = concat("前缀", field_name);
添加后缀
UPDATE `table` SET field_name = concat(field_name, "后缀");
批量替换
UPDATE `table` SET field_name = REPLACE(intro, "before_replace", "after_replace");
为了让各位更加清楚我们看几个例子
添加前缀
update `ecs_goods` set goods_name=concat('新中式',goods_name) where cat_id =4;
添加后缀
update `ecs_goods` set goods_name=concat(goods_name,'新中式') where cat_id =4;
删除
update `ecs_goods`set goods_name=right(goods_name,length(goods_name)-1) where cat_id =4;
其中ecs_goods为表名,cat_id为分类字段名,goods_name为产品字段名
本文介绍了如何在MySQL中使用concat()函数添加前缀和后缀到字段,以及如何通过REPLACE()函数进行批量替换。实例涵盖ecs_goods表中的商品名称操作,适用于数据库管理员和开发者参考。

612

被折叠的 条评论
为什么被折叠?



