首页 > 数据库技术 > 详细

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

时间:2014-10-29 16:49:19      阅读:361      评论:0      收藏:0      [点我收藏+]
MySql的like语句中的通配符:百分号、下划线和escape
%代表随意多个字符
select * from user where username like ‘%huxiao‘;
select * from user where username like ‘huxiao%‘;
select * from user where username like ‘%huxiao%‘;
_代表一个字符
Sql代码
select * from user where username like ‘_‘;
select * from user where username like ‘huxia_‘;
select * from user where username like ‘h_xiao‘;
假设我就真的要查%或者_,怎么办呢?使用escape,转义字符后面的%或_就不作为通配符了,注意前面没有转义字符的%和_仍然起通配符作用
Sql代码
select username from gg_user where username like ‘%xiao/_%‘ escape ‘/‘;
select username from gg_user where username like ‘%xiao/%%‘ escape ‘/‘;

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

原文:http://www.cnblogs.com/lcchuguo/p/4059581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!