在 MySQL 中将列转换为区分大小写的排序规则?
mysqlmysqli database
为此,您可以使用 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)