mysql 檢查字串是否包含子串

來源:互聯網
上載者:User

標籤:

1、使用substring_index(src,target,index) 從src的開頭尋找第index個target。返回的substring為從src的開頭到第num個target這段字串。比如substring_index(‘absscdessfss‘,‘ss‘,1) 返回absubstring_index(‘absscdessfss‘,‘ss‘,2) 返回absscdesubstring_index(‘absscdessfss‘,‘tt‘,1) 返回absscdessfss因此,檢查字串是否包含子串,使用substring_index(‘absscdessfss‘,‘tt‘,1) 看他返回是不是一個子串,是子串說明包含,返回的是原來完成的字串,說明不包含。length(src) - length(substring_index(src,target,1)) >0 說明包含。2、第二種辦法,把target替換為空白字串,如果存在target,則替換後的長度必定小於原來的長度length(src) - length(replace(src,target,‘‘)) >0 說明包含。進一步思考,還可以計算包含幾個子串,長度的差值除以target的長度,就是包含子串的個數。select (length(src) - length(replace(src,target,‘‘)))/length(target);

mysql 檢查字串是否包含子串

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.