MySQL LIKE 语句解释“o”和“ö”一样
我有一个连接到 MySQL 数据库的 Rails 3 应用程序。使用的编码是utf-8。该数据库连接了大量瑞典语数据,并具有搜索功能。
当我搜索 gotland
(瑞典岛屿)时,也会返回 Östergötland
(郡)结果。显然 MySQL 将 ö
解释为 o
。
有没有一种简单的方法可以确保 location LIKE '%gotland%'
不会返回包含 götland
的字段?
干杯。
I have a Rails 3 application connected to a MySQL-database. The encoding used is utf-8. The database connects a lot of data in Swedish and has a search function.
When I search for gotland
(a Swedish island) results for Östergötland
(a shire) is returned as well. Apparently MySQL interprets ö
as o
.
Is there a simple way to make sure that location LIKE '%gotland%'
does not return fields containing götland
?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信通过在
LIKE
语句后添加COLLATE utf8_swedish_ci
,您会得到您想要的。或者,如果
latin1
是您的字符集,您可能需要使用latin1_swedish_ci
。我不能 100% 确定这会修复
LIKE
语句中的字符比较,但逻辑上应该如此。来源:
I believe that by adding
COLLATE utf8_swedish_ci
after theLIKE
statement, you will get what you want.Alternately, you might want to use
latin1_swedish_ci
iflatin1
is your character set.I am not 100% certain that this fixes character comparison in a
LIKE
statement, but it logically should.Sources: