like有两个模式:_和%git
select name from table where name like '陈__';
select name from table where name like '陈%'; select name from table where name like '%宏%';
1.基本字符匹配正则表达式
select * from table where col regexp '.000';
2.like匹配整个值 通配符%spa
3.regexp可以使用正则自由定制 定位符号^$
4.若是要区分大小写,应该使用BINARY关键字,如where xxx REGEXP BINARY 'Hello.000'
5.使用|实现or效果code
select * from table where col regexp '1000|2000';
6.匹配几个字符之一,用[和]扩起来regexp
select * from table where col regexp '[abcde]';
7.匹配范围:[0-9] [A-Z] [a-z]blog
select * from table where col regexp '[0-9]Ton';
8.匹配特殊字符使用\\进行转义it
注意:
a)为了匹配\自己,须要使用\\\
b)在通常状况下正则表达式的转义加一个“\”就能够了,在MySQL中须要加两个。table
9.匹配字符类(Posix字符类)class
使用的时候须要外面加一层[],例如[[:digit:]]变量
select * from table where col regexp 'name[[:digit:]]';
10.匹配多个实例
select * from table where col regexp '[0-9]{1,3}';
11.定位符
12.^有两个用法,一个是非,一个是文本的开始,用[]中表示非,不然是文本的开始。
13.MySQL的正则比较简化,没有惰性匹配/贪婪匹配,[]内不支持\w\s\d这种语法,也不支持中文。
14.这两种模式不要混着用,like模式是不支持正则表达式的,REGEXP模式也不认识_和%。
15.注意:regexp == rlike 同义词 not like not regexp
16.in不支持模糊查询,如:
select * from table where name in ('%宏%');
17.like concat('%',name,'%')做用在于name为变量,在传参的时候方便。
END 2018-06-01 15:00:02