今天我们来学习一下模糊查询,那么我们先认识以下几个通配符的含义
_ | 表任意的单个字符 |
% | 表示多个任意字符 |
^ | 表示非 |
[] | 表示筛选范围,[]可以将通配符进行转 |
_ 任意单个字符 % 表示任意多个字符
--查找姓冯,且名字为两个字,姓名长度为二
select * from T_table where name like'冯_'
--查找姓冯,且名字为三个字,姓名长度为三
select * from T_table where name like'冯__'
--查找长度为三,且为冯什么星的人
select * from T_table where name like'冯_星'
--查找姓冯
select * from T_table where name like'冯%'
效果展示:
[]:表示筛选范围,^表示非
select * from T_table where name like'冯[0-9]星'
select * from T_table where name like'冯[a-z]星'
select * from T_table where name like'冯[a-z 0-9]星'
select * from T_table where name like'冯[^0-9]星'--非数字
select * from T_table where name not like'冯[0-9]星'--非数字
select * from T_table where name like'%[@]%'
效果展示:
注意,我们知道模糊查询是针对字符串查询的操作,如果查询当中存在通配符该怎么办?
--自定义转义符号 ESCAPE'/'例如我自定义转义符号位/,/后边是我匹配的字符串
--查找所有带[ 的人
select * from T_table where name like'%/[%'ESCAPE'/'
--查找所有带] 的人
select * from T_table where name like'%/]%'ESCAPE'/'
--查找所有带[]的人
select * from T_table where name like'%/[/]%'ESCAPE'/'
关于模糊查询就先分享到这里,如果本篇博客对您有所帮助,记得点赞哦!