mysql中字符查询与替换

select * from tablename where column like "%str%"----------------------查询表中的某列里包含某str的行

update tablename set content=concat(left(content,instr(url,'['-1),right(content,length(content)-instr(content,']')))
where instr(content,'['>0 and instr(content,']'>instr(content,'[')----------替换表中某列里包含的指定字符

update tablename set column =replace(column,'str','')-------------------替换表中某列里内容为str的字符串

update table set content=left(content,locate('str',content)+1)-----------删除表中某列里str后的内容

select trim(leading 'x' from 'xxxadminxxx')-----------------------------------删除字符串xxxadminxxx前xxx

select trim(trailing 'x' from 'xxxadminxxx')---------------------------------- -删除字符串xxxadminxxx后xxx 

select trim(both 'x' from 'xxxadminxxx')---------------------------------------删除字符串xxxadminxxx前后的xxx

delete from `表` where `字段` not like '%指定字符1%'--------------------删除不包含某字符串的记录

delete from `表` where `字段` like '%指定字符1%' or like '%指定字符2%' or like '%指定字符3%'------------删除包含某字符串的记录

猜你喜欢

转载自www.cnblogs.com/josn1984/p/9358998.html