MYSQL数据库字段模糊替换

MYSQL数据库字段模糊替换,第1张

您好,update mt2 set name = replace(name, substring(name, locate('<contact>', name),locate('</contact>', name)-locate('<contact>'+10, name)),'')

locate:

LOCATE(substr,str)

POSITION(substr IN str)

返回子串 substr 在字符串 str 中第一次出现的位置。如果子串 substr 在 str 中不存在,返回值为 0:

substring

SUBSTR(str,pos,len): 由<str>中的第<pos>位置开始,选出接下去的<len>个字元。

replace

replace(str1, str2, str3): 在字串 str1 中,当 str2 出现时,将其以 str3 替代。

group_contact刚好满足你的这个要求哦

数据库的结构如下:

noitem

01AA

01BB

02CC

02DD

02EE

03FF

04GG

04HH

希望将no相同的列整合为一条记录如下

noitems

01AA,BB

02CC,DD,EE

03FF

04GG,HH

MYSQL中,直接有group_contact函数了,如下:

select id,group_contact(items) from TABLE group by id


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7642083.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存