如何删除 MySQL 中的重音符号? [英] How to remove accents in MySQL?

查看:41
本文介绍了如何删除 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)

这篇关于如何删除 MySQL 中的重音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆