問題描述
嘗試通過 MySQL 中的存儲過程進行選擇時出現以下錯誤.
Am getting the below error when trying to do a select through a stored procedure in MySQL.
排序規則 (latin1_general_cs,IMPLICIT) 和 (latin1_general_ci,IMPLICIT) 的非法混合用于操作 '='
Illegal mix of collations (latin1_general_cs,IMPLICIT) and (latin1_general_ci,IMPLICIT) for operation '='
知道這里可能出了什么問題嗎?
Any idea on what might be going wrong here?
表的排序規則是latin1_general_ci
,where子句中列的排序規則是latin1_general_cs
.
The collation of the table is latin1_general_ci
and that of the column in the where clause is latin1_general_cs
.
推薦答案
這通常是由于比較兩個不兼容的排序規則的字符串或嘗試將不同排序規則的數據選擇到組合列中引起的.
This is generally caused by comparing two strings of incompatible collation or by attempting to select data of different collation into a combined column.
子句 COLLATE
允許您指定查詢中使用的排序規則.
The clause COLLATE
allows you to specify the collation used in the query.
例如,以下 WHERE
子句將始終給出您發布的錯誤:
For example, the following WHERE
clause will always give the error you posted:
WHERE 'A' COLLATE latin1_general_ci = 'A' COLLATE latin1_general_cs
您的解決方案是為查詢中的兩列指定共享排序規則.下面是一個使用 COLLATE
子句的例子:
Your solution is to specify a shared collation for the two columns within the query. Here is an example that uses the COLLATE
clause:
SELECT * FROM table ORDER BY key COLLATE latin1_general_ci;
另一種選擇是使用 BINARY
運算符:
Another option is to use the BINARY
operator:
BINARY str 是 CAST(str AS BINARY) 的簡寫.
BINARY str is the shorthand for CAST(str AS BINARY).
您的解決方案可能如下所示:
Your solution might look something like this:
SELECT * FROM table WHERE BINARY a = BINARY b;
或者,
SELECT * FROM table ORDER BY BINARY a;
這篇關于排查“非法混合排序規則"mysql 中的錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!