mysql判断一个字符串是否包含某子串【转】

来源:互联网 发布:充电宝排行知乎 编辑:程序博客网 时间:2024/05/22 14:06
使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 

例子:判断site表中的url是否包含'http://'子串,如果不包含则拼接在url字符串开头
update site set url =concat('http://',url) where locate('http://',url)=0 

注意mysql中字符串的拼接不能使用加号+,用concat函数
0 0