MySQL查询语句查询条件严格匹配大小写

感谢博客http://snowolf.iteye.com/blog/1681944,同时向各位推荐一下这个snowWolf的博客

以前就想到过SQL查询时如何严格匹配查询条件的大小写,只是都是一瞬的想法,并没有在实际中用到或者专门查过

开始

1 create table user (
2      id int primary key,
3      name varchar(30)      
4 );
5 insert into user (id,name) values (1,'AAA');
6 insert into user (id,name) values (2,'BBB');
7 insert into user (id,name) values (3,'aaa');
8 insert into user (id,name) values (4,'bbb');

查询语句,只差一个单词binary

1 select * from user where name like '%A%';  
2 select * from user where name like '%a%';        ##与第一句执行效果一样
3 select * from user where binary name like '%A%';    --只匹配大写A  
4 select * from user where binary name like '%a%';    --只匹配小写a

 

另外:见表时可以强制区分大小写

1 create table user (
2      name varchar(10) binary
3 );
4 insert into user (name) values ('AAA');

执行SQL

1 select * from user where name like '%a%';        --结果为空
2 select * from user where name like '%A%';          --可以查出来

 

 

 

posted @ 2013-09-01 22:48  dirkmurphyjava  阅读(3293)  评论(0编辑  收藏  举报