24-11 模糊查询

模糊查询——针对字符串

--模糊查询:
--通配符:_   %   []   ^


-- _ 表示任意的单个字符

--姓张,两个字的
select * from TblStudent where tsname like '张_'

--姓张,三个字的
select * from TblStudent where tsname like '张__'



-- % 匹配任意多个任意字符
--无论姓名字数,只要第一个字符是'张'的就查询出来
select * from TblStudent where tsname like '张%'

select * from TblStudent where tsname like '张%' and len(tsname)=2




-- [] 表示筛选,范围
select * from TblStudent where tsname like '张[0-9]妹'

select * from TblStudent where tsname like '张_妹'

select * from TblStudent where tsname like '张[a-z]妹'

select * from TblStudent where tsname like '张[a-z0-9]妹'

select * from TblStudent where tsname like '张[^0-9]妹'

  

--查询姓名中包含%的那些人
--通配符放到[]中就转义了就不认为是通配符了
select * from TblStudent where tsname like '%[%]%'


--where column A like '%S/%%' Escape '/'
select * from TblStudent where tsname like '%/]%' Escape '/'
select * from TblStudent where tsname like '%/[%' Escape '/'
select * from TblStudent where tsname like '%/[%/]%' Escape '/'

 

posted @ 2017-07-19 00:58  Strugglinggirl  阅读(172)  评论(0编辑  收藏  举报