今天遇到一个需求就是搜索时,需要进行忽略大小写。比如用户输入的关键词是a,那么查询出来的结果中也要有A的结果。
解决办法:
1.mysql 中查询默认是不区分大小写的
如:
select * from some_table where str=‘abc’; select * from some_table where str=’ABC’;
得到的结果是一样的,如果我们需要进行区分的话可以按照如下方法来做:
第一种方法:
要让mysql查询区分大小写,可以:
select * from some_table where binary str=’abc’ select * from some_table where binary str=’ABC’
第二方法:
在建表时时候加以标识
create table some_table( str char(20) binary )