mysql数据库中如何进行模糊替换字符串
发布网友
发布时间:2022-04-27 13:17
我来回答
共2个回答
热心网友
时间:2022-04-08 05:15
您好,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 替代。
热心网友
时间:2022-04-08 06:33
UPDATE goods SET
goods_name = CONCAT(LEFT(goods_name,LOCATE('(', goods_name)),'公斤)')
WHERE goods_name LIKE '%(%)'