码迷,mamicode.com
首页 > 其他好文 > 详细

like

时间:2017-09-17 21:05:36      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:where   没有   类型   字符   使用   通配符   红色   sel   nbsp   

like语句的通配符:百分号、下划线和escape

1.1.  %: 表示任意一个或多个字符,可匹配任意类型和长度的字符

e.g.  
select  *  from user where username like ‘%san‘ ;               名字 结尾是  san  的记录
select  *  from user where username like ‘zhang%‘ ;            名字开头是   zhang  的记录
select  *  from user where username like ‘%san%‘ ;             名字含 san  的记录
select  *  from user where username like ‘%san%‘   and  username like ‘%zhang%‘;      名字中既有san又有 zhang的记录

1.2. _:表示任意单个字符

select * from user where username like ‘_‘;               名字只有一个字符的记录
select * from user where username like ‘huxia_‘;       名字以huxia  开头,结尾有一个字符的记录
select * from user where username like ‘h_xiao‘;       

1.3. escape: 若要查%或者_,可以使用escape,转义字符后面的%或_就不作为通配符

e.g. 
select username from gg_user where username like ‘%xiao/_%‘ escape ‘/‘;     注意,此处红色的_只能表示_,而没有通配符的功能
select username from gg_user where username like ‘%xiao/%%‘ escape ‘/‘;      此处红色的%只能表示%,而没有通配符的功能

like

标签:where   没有   类型   字符   使用   通配符   红色   sel   nbsp   

原文地址:http://www.cnblogs.com/zhu-tingting/p/7536907.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!