zoukankan      html  css  js  c++  java
  • 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%';          --可以查出来
  • 相关阅读:
    mysql 远程登陆不上
    hdu 5339 Untitled【搜索】
    SqlServer 书目
    passwordauthentication yes
    oracle 11g RAC ocfs2
    Oracle 11g RAC database on ASM, ACFS or OCFS2
    CentOS ips bonding
    Oracle 11g RAC features
    openStack 王者归来之 trivial matters
    openstack windows 2008 img
  • 原文地址:https://www.cnblogs.com/dirkmurphyjava/p/3295621.html
Copyright © 2011-2022 走看看