默认字符集和排序规则为latin1和latin1_swedish_ci,因此默认情况下非二进制字符串比较不区分大小写.这意味着,如果使用col_name LIKE'a%'搜索,则将获得所有以A或a开头的列值.要使此搜索区分大小写,请确保其中一个操作数具有区分大小写或二进制排序规则.例如,如果要比较均具有latin1字符集的列和字符串,则可以使用COLLATE运算符使两个操作数具有latin1_general_cs或latin1_bin排序规则:
The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:
col_name COLLATE latin1_general_cs LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_general_cs
col_name COLLATE latin1_bin LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_bin
如果希望始终以区分大小写的方式对待列,请使用区分大小写或二进制排序规则对其进行声明.
If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation.
这篇关于如何在MySQL上进行SQL区分大小写的字符串比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!