MySQL - 为什么LIKE运算符忽略了COLLATION规则的德语ß字符

时间:2021-10-11 11:05:27

I'm running the following select statements on MySQL 5.0.88 with utf8 charset and utf8_unicode_ci collation:

我在MySQL 5.0.88上使用utf8 charset和utf8_unicode_ci collat​​ion运行以下select语句:

SELECT * FROM table WHERE surname = 'abcß';

+----+-------------------+------+
| id | forename    | surname    |
+----+-------------------+------+
|  1 | a           | abcß       |
|  2 | b           | abcss      |
+----+-------------+------------+

SELECT * FROM table WHERE surname LIKE 'abcß';

+----+-------------------+------+
| id | forename    | surname    |
+----+-------------------+------+
|  1 | a           | abcß       |
+----+-------------+------------+

According to http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html the german special char ß = ss for utf8_unicode_ci, but why does it only work with the "=" operator and not with LIKE? I have a phone book application and I desperately need both things working together.

根据http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html德国特殊字符ß= ss表示utf8_unicode_ci,但为什么它只适用于“=”运算符和不喜欢?我有一个电话簿应用程序,我迫切需要两个一起工作。

1 个解决方案

#1


10  

Per the SQL standard, LIKE performs matching on a per-character basis, thus it can produce results different from the = comparison operator:

根据SQL标准,LIKE基于每个字符执行匹配,因此它可以产生与=比较运算符不同的结果:

mysql> SELECT 'ä' LIKE 'ae' COLLATE latin1_german2_ci;
+-----------------------------------------+
| 'ä' LIKE 'ae' COLLATE latin1_german2_ci |
+-----------------------------------------+
|                                       0 |
+-----------------------------------------+
mysql> SELECT 'ä' = 'ae' COLLATE latin1_german2_ci;
+--------------------------------------+
| 'ä' = 'ae' COLLATE latin1_german2_ci |
+--------------------------------------+
|                                    1 |
+--------------------------------------+

Source: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

资料来源:http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

#1


10  

Per the SQL standard, LIKE performs matching on a per-character basis, thus it can produce results different from the = comparison operator:

根据SQL标准,LIKE基于每个字符执行匹配,因此它可以产生与=比较运算符不同的结果:

mysql> SELECT 'ä' LIKE 'ae' COLLATE latin1_german2_ci;
+-----------------------------------------+
| 'ä' LIKE 'ae' COLLATE latin1_german2_ci |
+-----------------------------------------+
|                                       0 |
+-----------------------------------------+
mysql> SELECT 'ä' = 'ae' COLLATE latin1_german2_ci;
+--------------------------------------+
| 'ä' = 'ae' COLLATE latin1_german2_ci |
+--------------------------------------+
|                                    1 |
+--------------------------------------+

Source: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

资料来源:http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like