mysql 判断字符在的位置 mysql字符串判断
转载
- like 也就是模糊查询 如:select * from user where user_name '%李%'
- locate 判断是否包含某字符串 如:select * from user where locate('李',user_name)>0
- position 判断是否包含某字符串 如:select * from user where position('李' in user_name)>0
- instr 判断是否包含某字符串 如:select * from user where instr(user_name,'李')>0
- find_in_set 正好反过来,库里字段的值是否被包含在条件字符串里 如下:
select * from user where find_in_set (user_name,'李刚,刘备')>0
- 正则匹配两个字符串是否含有交集,我中有你,你中有我,如有共同部分,则返回数据,如下:
select * from user where user_name REGEXP REPLACE('李刚,刘备',',','|')
- CONCAT(',',str,',') 查询某字段中以逗号分隔的字符串的方法,好处是如果是数字逗号拼接的话,查询的参数是个位数的话,很容易查询出一大堆覆盖个位数的多位数数字
select * from user where CONCAT(',','李刚,刘备',',') like '%,刘备,%'
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。