我有一个函数返回五个字符与混合大小写。 如果我对这个字符串进行查询,它将返回值,而不管case。
如何使MySQL字符串查询区分大小写?
I have a function that returns five characters with mixed case. If I do a query on this string it will return the value regardless of case.
How can I make MySQL string queries case sensitive?
最满意答案
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
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默认字符集和排序规则为latin1和latin1_swedish_ci,因此默认情况下,非二进制字符串比较不区分大小写。 这意味着如果您使用col_name LIKE'a%'搜索,则会获得以A或a开头的所有列值。 要使此搜索大小写敏感,请确保其中一个操作数具有区分大小写或二进制排序规则。 例如,如果要比较列和两个都具有latin1字符集的字符串,则可以使用COLLATE运算符使任意一个操作数具有latin1_general_cs或latin1_bin排序规则:
如果你想要一个总是以区分大小写的方式对待一个列,用一个区分大小写或二进制排序规则来声明它。
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
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_binThe 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:
If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation.
更多推荐
发布评论