MySQL DB selects records with and without umlauts. e.g: '.. where something = FÖÖ'

萝らか妹 提交于 2019-12-19 06:55:07

问题


My Table collation is "utf8_general_ci". If i run a query like:

SELECT * FROM mytable WHERE myfield = "FÖÖ"

i get results where:

...  myfield = "FÖÖ"
...  myfield = "FOO"

is this the default for "utf8_general_ci"?

What collation should i use to only get records where myfield = "FÖÖ"?


回答1:


SELECT * FROM table WHERE some_field LIKE ('%ö%'  COLLATE utf8_bin)



回答2:


A list of the collations offered by MySQL for Unicode character sets can be found here:

http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html

If you want to go all-out and require strings to be absolutely identical in order to test as equal, you can use utf8_bin (the binary collation). Otherwise, you may need to do some experimentation with the different collations on offer.




回答3:


For scandinavian letters you can use utf8_swedish_ci fir example.

Here is the character grouping for utf8_swedish_ci. It shows which characters are interpreted as the same. http://collation-charts.org/mysql60/mysql604.utf8_swedish_ci.html

Here's the directory listing for other collations. I'm no sure which is the used utf8_general_ci though. http://collation-charts.org/mysql60/



来源:https://stackoverflow.com/questions/6279374/mysql-db-selects-records-with-and-without-umlauts-e-g-where-something-f%c3%96

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!