dua55014 2014-01-26 01:02
浏览 51
已采纳

对非拉丁字符不敏感的SQL查询?

Is there any way I can write a select query with where clause, that ignores non-latin characters?

For example there is Lithuanian character Ė, obviously the equivalent in latin character would be E. So is there anyway I can write a query like this:

SELECT * FROM `table` WHERE `keyword` LIKE %E%;

And I want it to return all records that contain any of these characters: E,Ė,Ę, is there any way I can achieve this automatically with SQL (or even in PHP level)?

  • 写回答

1条回答 默认 最新

  • douduandiao1368 2014-01-26 01:48
    关注

    You don't say what you've tried. You also don't say what character set (utf-8) and collation your table contains. Those are the ways you control those things by default.

    You could try this:

     SELECT * FROM `table` WHERE `keyword` COLLATE utf8_general_ci LIKE %E%
    

    Or this

     SELECT * FROM `table` WHERE `keyword` COLLATE utf8_lithuanian_ci LIKE %E%
    

    I don't know if the second one will work for what you want, because I don't know Lithuanian. Are E, Ė, and Ę considered the same letter in the dictionary? If they are not, then the Lithuanian collation won't match them to each other.

    If you do find that a particular collation works, you can alter your column to use that collation by default.

    alter table `table`
      change `keyword` `keyword` collate utf8_lithuanian_ci
    

    That's a good idea because then you have a chance of indexes speeding your search.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?