MySQL如何进行区分大小写的字符串比较?
短信预约 -IT技能 免费直播动态提醒
As we know that MySQL is not case-sensitive while comparing characters but it can be changed i.e. MySQL can perform case-sensitive string comparison if we will use BINARY keyword before the expression. Actually, BINARY keyword instructs MySQL to compare the characters in the string using their underlying ASCII values rather than just their letters. It can be illustrated with the following example from table ‘Employee’ having the following data −
mysql> Select * from Employee;
+----+--------+--------+
| ID | Name | Salary |
+----+--------+--------+
| 1 | Gaurav | 50000 |
| 2 | Rahul | 20000 |
| 3 | Advik | 25000 |
| 4 | Aarav | 65000 |
| 5 | Ram | 20000 |
| 6 | Mohan | 30000 |
| 7 | Aryan | NULL |
| 8 | Vinay | NULL |
+----+--------+--------+
8 rows in set (0.09 sec)
下面的查询将使用BINARY关键字来强制MySQL执行区分大小写的字符串比较。
mysql> Select * from Employee WHERE BINARY Name IN ('Gaurav','RAM');
+----+--------+--------+
| ID | Name | Salary |
+----+--------+--------+
| 1 | Gaurav | 50000 |
+----+--------+--------+
1 row in set (0.00 sec)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341