doudang4568 2016-05-13 21:41
浏览 159
已采纳

Mysql自然排序与特殊字符

Good morning, this is my first topic, so thanks for all outcoming help.

I'm working in a Yii application with a MySQL database. This database has a countries table that has a column called name with a utf8_general_ci collation. This column is filled by data with special characters as Åland Islands

Using the Mysql regular sorting, the column name doesn't have a correct sorting behaviour, for example:

Correct:
Albania
Åland Islands

Actual:
Åland Islands
Albania

Referencing to ASCII table, 'Å' is 197 instead of 'A' is 65.

I tried to use many solutions from the Web (including REGEXP), without success.

  • 写回答

1条回答 默认 最新

  • douyue9704 2016-05-13 22:53
    关注

    In utf8_general_ci, the order of the different sorts of a (a, A, à, ä, etc) is not differenciated : they are all equal in sorting, you can see in the precedent linked page that they are all in white boxes after the letter A.

    If you want a sort order corresponding to a specific language, you need to choose the collation corresponding to that language, here may be the utf8_swedish_ci where you can see that the ä and å are at the end of the alphabet.

    This is because the sorting order is not the same in different languages, and utf8_general_ci cannot choose one and not the other. For example, in utf8_swedish_ci, Å is before Ä, and in utf8_icelandic_ci, the Å is after the Ä.

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。