模糊查询

模糊查询是针对字符串操作的,类似正则表达式,没有正则表达式强大

通配符:_ 、% 、[] 、

_ 表示任意的单个字符

--查询MyStudent表中任意姓张,名字两个字的姓名
select * from MyStudent where fname like '张_'
--查询MyStudent表中任意姓张,名字三个字的姓名
select * from MyStudent where fname like '张__'

%表示匹配任意多个任意字符

--查询MyStudent表中任意姓张的(第一个为张)的姓名字数不限的姓名
select * from MyStudent where fname like '张%'
--查询MyStudent表中姓张的名字两个字的
select * from MyStudent where fname like '张%'and len(fname) = 2

[]表示筛选范

--查询表中所有姓张第二个为数字第三个为妹的名字
select * from MyStudent where fname like '张[0-9]妹'

select * from MyStudent where fname like '张[a-z]妹'

select * from MyStudent where fname like '张[0-9a-z]妹'--中间为1个字母和和1个数字,字母大小写可以通过约束设定,不区分大小写

select * from MyStudent where fname like '张[!0-9]妹' --中间不为数字

select * from MyStudent where fname not like '张[0-9]妹'--不能以张开头妹结尾中间不能是数字同上不一样
--查询出表中包含通配符%的姓名 

 select * from MyStudent where fname  like '%[%]%'--通配符放到[]中就转义了不是通配符了

 
--查询表中包含[的姓名
 select * from MyStudent where fname  like '%/[%' escape '/' --指定通配符为/

--查询表中包含通配符[]的姓名
 select * from MyStudent where fname  like '%/[/]%' escape '/' --指定通配符为/

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值