MySQL uses coercibility values with the following rules to resolve ambiguities:
Use the collation with the lowest coercibility value.
If both sides have the same coercibility, then:
If both sides are Unicode, or both sides are not Unicode, it is an error.
If one of the sides has a Unicode character set, and another side has a non-Unicode character set, the side with Unicode character set wins, and automatic character set conversion is applied to the non-Unicode side. For example, the following statement does not return an error:
SELECT CONCAT(utf8_column, latin1_column) FROM t1;
问题中给出的特定错误Illegal mix of collations (latin1_general_cs,IMPLICIT) and (latin1_general_ci,IMPLICIT) for operation '='告诉我们,两个具有相同强制力的非unicode字符串之间存在相等比较。它进一步告诉我们,排序规则不是在语句中显式给出的,而是从字符串的来源(例如列元数据)中暗示出来的
一个“系统常数”(由< A href="http://dev.mysql.com/doc/en/information-functions.html#function_user">USER() A >或< A href="http://dev.mysql.com/doc/en/information-functions.html#function_version">VERSION() A >等函数返回的字符串)的可强制值为3。
CREATE OR REPLACE VIEW hr_cc_normalised_data_date_v AS
SELECT convert('X' using latin1) COLLATE latin1_general_cs AS PSEUDO_KEY
, DATA_DATE
FROM HR_COSTCENTRE_NORMALISED_mV
LIMIT 1;
如果“哈希”是一个十六进制字符串,你不需要utf8,应该避免这样做,因为字符检查等。例如,MySQL的MD5(...)产生一个固定长度的32字节十六进制字符串。SHA1(...)给出了一个40字节的十六进制字符串。这可以存储在CHAR(32) CHARACTER SET ascii(或sha1的40)中。