在 MySQL 中将列转换为大小写敏感的整理规则?
为此目的,可使用 COLLATE。语法如下 −
select *from yourTableName where yourColumnName LIKE yourValue COLLATE utf8_bin;
首先,创建表 −
mysql> create table DemoTable ( LastName varchar(100) ); Query OK, 0 rows affected (0.51 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('BROWN'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('BRoWN'); Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
+----------+ | LastName | +----------+ | Brown | | BROWN | | brown | | BRoWN | +----------+ 4 rows in set (0.00 sec)
COLLATE 的查询如下 −
mysql> select *from DemoTable where LastName LIKE 'BROWN' COLLATE utf8_bin;
输出
+----------+ | LastName | +----------+ | BROWN | +----------+ 1 row in set (0.00 sec)
广告