mysql 如何根据中文拼音首字母进行中文查询?

2020-10-20 10:22:45 +08:00
 Vimax

数据库有个字段保存了中文名称,比如:

  1. 张三
  2. 本山
  3. 赵本山 ...

现在想通过拼音首字母进行模糊查询:

比如

ZS: 可以查询到张三

BS:可以查找到本山赵本山

请教,

在数据库已经存在中文名称的数据,且没有保存中文拼音和首字母拼音的前提下。

如何使用 mysql 根据中文名称进行拼音首字母查询到数据。

3635 次点击
所在节点    MySQL
11 条回复
Caskia
2020-10-20 10:28:14 +08:00
是什么阻碍了你建立拼音和首字母列?
opengps
2020-10-20 10:30:32 +08:00
这种查询一般需要单独一个列来存储首字母,而不是让数据库具备转换拼音能力
hbolive
2020-10-20 10:59:50 +08:00
抱歉,开发 MySQL 的人,不认识拼音在这个东东。。
angeltop
2020-10-20 11:11:55 +08:00
哈哈,这个国产数据库软件应该是支持的。
lskjdfgl
2020-10-20 11:13:21 +08:00
mysql 默认支持拼音查询, 你可以查下文档
xsm1890
2020-10-20 11:14:04 +08:00
hahahahahhahahahahaah
GuangXiN
2020-10-20 11:27:38 +08:00
现在能找到开源的库把汉字转换成拼音吧
lasuar
2020-10-20 11:31:04 +08:00
别急,这就给 mysql 提 issue
JaguarJack
2020-10-20 13:52:15 +08:00
你在建个拼音列不就好了吗
zhangysh1995
2020-11-02 16:46:06 +08:00
@lskjdfgl 老哥厉害了,我去看文档了,还真支持 https://dev.mysql.com/doc/mysql-g11n-excerpt/5.7/en/charset-gb18030.html
gb18030_chinese_ci: The default collation, which supports Pinyin. Sorting of non-Chinese characters is based on the order of the original sort key. The original sort key is GB(UPPER(ch)) if UPPER(ch) exists. Otherwise, the original sort key is GB(ch). Chinese characters are sorted according to the Pinyin collation defined in the Unicode Common Locale Data Repository (CLDR 24). Non-Chinese characters are sorted before Chinese characters with the exception of GB+FE39FE39, which is the code point maximum.
q344766620
2022-07-28 21:35:23 +08:00
@zhangysh1995 这是按照拼音排序,无法通过拼音搜索数据库。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/716607

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX