SQLserver—模糊查询

今天我们来学习一下模糊查询,那么我们先认识以下几个通配符的含义

 _表任意的单个字符
%表示多个任意字符
^表示非
 []表示筛选范围,[]可以将通配符进行转


 _ 任意单个字符  % 表示任意多个字符

--查找姓冯,且名字为两个字,姓名长度为二
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'/'

关于模糊查询就先分享到这里,如果本篇博客对您有所帮助,记得点赞哦!

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值