Version sans cache

Mise en cache désactivé. Réglage défaut pour cette page : actif (code DEF204)
Si l'affichage est trop lent, vous pouvez désactiver le mode utilisateur pour visualiser la version en cache.

Rechercher dans le manuel MySQL

10.8.6 Examples of the Effect of Collation

Example 1: Sorting German Umlauts

Suppose that column X in table T has these latin1 column values:

Muffler
Müller
MX Systems
MySQL

Suppose also that the column values are retrieved using the following statement:

  1. SELECT X FROM T ORDER BY X COLLATE collation_name;

The following table shows the resulting order of the values if we use ORDER BY with different collations.

latin1_swedish_ci latin1_german1_ci latin1_german2_ci
Muffler Muffler Müller
MX Systems Müller Muffler
Müller MX Systems MX Systems
MySQL MySQL MySQL

The character that causes the different sort orders in this example is the U with two dots over it (ü), which the Germans call U-umlaut.

  • The first column shows the result of the SELECT using the Swedish/Finnish collating rule, which says that U-umlaut sorts with Y.

  • The second column shows the result of the SELECT using the German DIN-1 rule, which says that U-umlaut sorts with U.

  • The third column shows the result of the SELECT using the German DIN-2 rule, which says that U-umlaut sorts with UE.

Example 2: Searching for German Umlauts

Suppose that you have three tables that differ only by the character set and collation used:

  1. mysql> SET NAMES utf8;
  2. mysql> CREATE TABLE german1 (
  3.          c CHAR(10)
  4.        ) CHARACTER SET latin1 COLLATE latin1_german1_ci;
  5. mysql> CREATE TABLE german2 (
  6.          c CHAR(10)
  7.        ) CHARACTER SET latin1 COLLATE latin1_german2_ci;
  8. mysql> CREATE TABLE germanutf8 (
  9.          c CHAR(10)
  10.        ) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Each table contains two records:

  1. mysql> INSERT INTO german1 VALUES ('Bar'), ('Bär');
  2. mysql> INSERT INTO german2 VALUES ('Bar'), ('Bär');
  3. mysql> INSERT INTO germanutf8 VALUES ('Bar'), ('Bär');

Two of the above collations have an A = Ä equality, and one has no such equality (latin1_german2_ci). For that reason, you'll get these results in comparisons:

  1. mysql> SELECT * FROM german1 WHERE c = 'Bär';
  2. +------+
  3. | c    |
  4. +------+
  5. | Bar  |
  6. | Bär  |
  7. +------+
  8. mysql> SELECT * FROM german2 WHERE c = 'Bär';
  9. +------+
  10. | c    |
  11. +------+
  12. | Bär  |
  13. +------+
  14. mysql> SELECT * FROM germanutf8 WHERE c = 'Bär';
  15. +------+
  16. | c    |
  17. +------+
  18. | Bar  |
  19. | Bär  |
  20. +------+

This is not a bug but rather a consequence of the sorting properties of latin1_german1_ci and utf8_unicode_ci (the sorting shown is done according to the German DIN 5007 standard).


Rechercher dans le manuel MySQL

Traduction non disponible

Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-charset-collation-effect.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :en Manuel MySQL : https://dev.mysql.com/

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut