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 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作