mysql中字符查询与替换
select * from tablename where column like "%str%"----------------------查詢(xún)表中的某列里包含某str的行
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[url=',content)-locate('[/url]', content)),'')----------替換content內(nèi)容里面以[url=開(kāi)始并以[/url]結(jié)束之間的所有字符
update tablename set column =replace(column,'str','')-------------------替換表中某列里內(nèi)容為str的字符串
update table set?content=left(content,locate('str',content)+1)-----------刪除表中某列里str后的內(nèi)容
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%'------------刪除包含某字符串的記錄
以下為mysql刪除兩字符間所有字符的測(cè)試過(guò)程,參考過(guò)程來(lái)源博客見(jiàn)最后備注:
update ear_bbs_threads_content set content = dbo.RegexReplace('<*>','',content,1,1);
update ear_bbs_threads_content set content =replace(content,'[url*url]','') where tid >=100 and tid <=1000
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[/url]', content)-locate('[url=',content)),'')
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[/url]', content))),'')
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[url=',content)-locate('[/url]', content)),'')
?測(cè)試過(guò)程參考博客地址:https://yq.aliyun.com/ziliao/69563
其過(guò)程詳細(xì)說(shuō)明為:
使用 SubString字符串截取函數(shù)
SubString(string, int, int)
返回第一個(gè)參數(shù)中從第二個(gè)參數(shù)指定的位置開(kāi)始、第三個(gè)參數(shù)指定的長(zhǎng)度的子字符串。
然后用update set即可達(dá)到刪除字符串的前兩個(gè)字符的效果
sql
update table set name= substring(name,3,len(name)-2);
解釋:更新table表中name字段
substring(name,3,len(name)-2);表示返回從name字段的第三個(gè)字符之后的所有字符
效果就是刪除前2個(gè)字符了
len(name)表示返回name字段的長(zhǎng)度
參考地址為百度知道的:https://zhidao.baidu.com/question/588857422353045925.html
轉(zhuǎn)載于:https://www.cnblogs.com/josn1984/p/9358998.html
總結(jié)
以上是生活随笔為你收集整理的mysql中字符查询与替换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python使用tkinter做界面之颜
- 下一篇: CGI,FastCGI,PHP-CGI,