如何删除 MySQL 中的重音符号?
我刚刚编译了一个包含 100 万个地名的数据库.我将在自动完成小部件中使用它来查找城市.很多这些地方都有重音......我希望能够在用户键入不带重音的名称时找到记录.
I've just compiled a database of 1 million place names. I'm going to use it in an auto-complete widget to look up cities. A lot of these places have accents... I want to be able to find records when a user types the name without an accent.
为了做到这一点,我在第 2 列中添加了名称的无重音副本.许多这些记录仍然是空白的,所以我想写一个查询来填充它们.这在直接的 MySQL 中可能吗?如果是,怎么办?
In order to do this, I've got a 2nd column with an unaccented copy of the name. Many of these records are still blank, so I want to write a query to fill them in. Is this possible in straight MySQL? If so, how?
推荐答案
如果您为列设置了适当的排序规则,那么该字段中的值将自然地与它的无重音等效值相等.
If you set an appropriate collation for the column then the value within the field will compare equal to its unaccented equivalent naturally.
mysql> SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT 'é' = 'e';
+------------+
| 'é' = 'e' |
+------------+
| 1 |
+------------+
1 row in set (0.05 sec)
相关文章