問題描述
我有一個函數返回五個大小寫混合的字符.如果我對該字符串進行查詢,無論大小寫,它都會返回該值.
如何使 MySQL 字符串查詢區分大小寫?
http://dev.mysql.com/doc/refman/5.0/en/case-sensitive.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_cscol_name COLLATE latin1_bin LIKE 'a%'col_name LIKE 'a%' COLLATE latin1_bin
<塊引用>
如果您希望始終以區分大小寫的方式處理列,請使用區分大小寫或二進制排序規則聲明它.
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
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 區分大小寫的字符串比較?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!