我在 MySQL 中有以下查询:
SELECT id FROM unicode WHERE `character` = 'a'
表 unicode
包含每个 unicode 字符以及一个 ID(它是整数编码值)。由于表的排序规则设置为 utf8_unicode_ci,我预计上述查询仅返回 97(字母“a”)。相反,它返回 119 行,其中包含许多类似“a”的字母的 ID:
a A ...
它似乎忽略了大小写和字符的多字节性质。
有什么想法吗?
最佳答案
如 Unicode Character Sets 下所述:
MySQL implements the
xxx_unicode_ci
collations according to the Unicode Collation Algorithm (UCA) described at http://www.unicode.org/reports/tr10/. The collation uses the version-4.0.0 UCA weight keys: http://www.unicode.org/Public/UCA/4.0.0/allkeys-4.0.0.txt.
full collation chart清楚地表明,在此排序规则中,基本字母的大多数变体都是等效的,无论其字母大小写或重音/装饰如何。
如果您只想匹配精确的字母,则应使用二进制排序规则,例如 utf8_bin
。
关于MySQL WHERE `character` = 'a' 匹配 a、A、à 等。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12431887/