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

转载地址:http://blog.sina.com.cn/s/blog_71e2015f01017pnl.html

使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 


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


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

猜你喜欢

转载自blog.csdn.net/y___y___/article/details/46906211