Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code DEF204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher dans le manuel MySQL

10.13.4.1 Defining a UCA Collation Using LDML Syntax

To add a UCA collation for a Unicode character set without recompiling MySQL, use the following procedure. If you are unfamiliar with the LDML rules used to describe the collation's sort characteristics, see Section 10.13.4.2, “LDML Syntax Supported in MySQL”.

The example adds a collation named utf8_phone_ci to the utf8 character set. The collation is designed for a scenario involving a Web application for which users post their names and phone numbers. Phone numbers can be given in very different formats:

+7-12345-67
+7-12-345-67
+7 12 345 67
+7 (12) 345 67
+71234567

The problem raised by dealing with these kinds of values is that the varying permissible formats make searching for a specific phone number very difficult. The solution is to define a new collation that reorders punctuation characters, making them ignorable.

  1. Choose a collation ID, as shown in Section 10.13.2, “Choosing a Collation ID”. The following steps use an ID of 1029.

  2. To modify the Index.xml configuration file. This file is located in the directory named by the character_sets_dir system variable. You can check the variable value as follows, although the path name might be different on your system:

    1. mysql> SHOW VARIABLES LIKE 'character_sets_dir';
    2. +--------------------+-----------------------------------------+
    3. | Variable_name      | Value                                   |
    4. +--------------------+-----------------------------------------+
    5. | character_sets_dir | /user/local/mysql/share/mysql/charsets/ |
    6. +--------------------+-----------------------------------------+
  3. Choose a name for the collation and list it in the Index.xml file. In addition, you'll need to provide the collation ordering rules. Find the <charset> element for the character set to which the collation is being added, and add a <collation> element that indicates the collation name and ID, to associate the name with the ID. Within the <collation> element, provide a <rules> element containing the ordering rules:

    <charset name="utf8">
      ...
      <collation name="utf8_phone_ci" id="1029">
        <rules>
          <reset>\u0000</reset>
          <i>\u0020</i> <!-- space -->
          <i>\u0028</i> <!-- left parenthesis -->
          <i>\u0029</i> <!-- right parenthesis -->
          <i>\u002B</i> <!-- plus -->
          <i>\u002D</i> <!-- hyphen -->
        </rules>
      </collation>
      ...
    </charset>
  4. If you want a similar collation for other Unicode character sets, add other <collation> elements. For example, to define ucs2_phone_ci, add a <collation> element to the <charset name="ucs2"> element. Remember that each collation must have its own unique ID.

  5. Restart the server and use this statement to verify that the collation is present:

    1. mysql> SHOW COLLATION WHERE Collation = 'utf8_phone_ci';
    2. +---------------+---------+------+---------+----------+---------+
    3. | Collation     | Charset | Id   | Default | Compiled | Sortlen |
    4. +---------------+---------+------+---------+----------+---------+
    5. | utf8_phone_ci | utf8    | 1029 |         |          |       8 |
    6. +---------------+---------+------+---------+----------+---------+

Now test the collation to make sure that it has the desired properties.

Create a table containing some sample phone numbers using the new collation:

  1. mysql> CREATE TABLE phonebook (
  2.          name VARCHAR(64),
  3.          phone VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_phone_ci
  4.        );
  5. Query OK, 0 rows affected (0.09 sec)
  6.  
  7. mysql> INSERT INTO phonebook VALUES ('Svoj','+7 912 800 80 02');
  8. Query OK, 1 row affected (0.00 sec)
  9.  
  10. mysql> INSERT INTO phonebook VALUES ('Hf','+7 (912) 800 80 04');
  11. Query OK, 1 row affected (0.00 sec)
  12.  
  13. mysql> INSERT INTO phonebook VALUES ('Bar','+7-912-800-80-01');
  14. Query OK, 1 row affected (0.00 sec)
  15.  
  16. mysql> INSERT INTO phonebook VALUES ('Ramil','(7912) 800 80 03');
  17. Query OK, 1 row affected (0.00 sec)
  18.  
  19. mysql> INSERT INTO phonebook VALUES ('Sanja','+380 (912) 8008005');
  20. Query OK, 1 row affected (0.00 sec)

Run some queries to see whether the ignored punctuation characters are in fact ignored for comparison and sorting:

  1. mysql> SELECT * FROM phonebook ORDER BY phone;
  2. +-------+--------------------+
  3. | name  | phone              |
  4. +-------+--------------------+
  5. | Sanja | +380 (912) 8008005 |
  6. | Bar   | +7-912-800-80-01   |
  7. | Svoj  | +7 912 800 80 02   |
  8. | Ramil | (7912) 800 80 03   |
  9. | Hf    | +7 (912) 800 80 04 |
  10. +-------+--------------------+
  11. 5 rows in set (0.00 sec)
  12.  
  13. mysql> SELECT * FROM phonebook WHERE phone='+7(912)800-80-01';
  14. +------+------------------+
  15. | name | phone            |
  16. +------+------------------+
  17. | Bar  | +7-912-800-80-01 |
  18. +------+------------------+
  19. 1 row in set (0.00 sec)
  20.  
  21. mysql> SELECT * FROM phonebook WHERE phone='79128008001';
  22. +------+------------------+
  23. | name | phone            |
  24. +------+------------------+
  25. | Bar  | +7-912-800-80-01 |
  26. +------+------------------+
  27. 1 row in set (0.00 sec)
  28.  
  29. mysql> SELECT * FROM phonebook WHERE phone='7 9 1 2 8 0 0 8 0 0 1';
  30. +------+------------------+
  31. | name | phone            |
  32. +------+------------------+
  33. | Bar  | +7-912-800-80-01 |
  34. +------+------------------+
  35. 1 row in set (0.00 sec)

Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-ldml-collation-example.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut