如何在MySQL上进行SQL区分大小写的字符串比较?(How can I make SQL case sensitive string comparison on MySQL?)

编程入门 行业动态 更新时间:2024-10-26 16:21:58
如何在MySQL上进行SQL区分大小写的字符串比较?(How can I make SQL case sensitive string comparison on MySQL?)

我有一个函数返回五个字符与混合大小写。 如果我对这个字符串进行查询,它将返回值,而不管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

默认字符集和排序规则为latin1和latin1_swedish_ci,因此默认情况下,非二进制字符串比较不区分大小写。 这意味着如果您使用col_name LIKE'a%'搜索,则会获得以A或a开头的所有列值。 要使此搜索大小写敏感,请确保其中一个操作数具有区分大小写或二进制排序规则。 例如,如果要比较列和两个都具有latin1字符集的字符串,则可以使用COLLATE运算符使任意一个操作数具有latin1_general_cs或latin1_bin排序规则:

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

如果你想要一个总是以区分大小写的方式对待一个列,用一个区分大小写或二进制排序规则来声明它。

http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html

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.

更多推荐

本文发布于:2023-07-30 21:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小写   字符串   如何在   SQL   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!