Rechercher dans le manuel MySQL
10.2.1 Character Set Repertoire
The repertoire of a character set is the collection of characters in the set.
String expressions have a repertoire attribute, which can have two values:
ASCII
: The expression can contain only characters in the Unicode rangeU+0000
toU+007F
.UNICODE
: The expression can contain characters in the Unicode rangeU+0000
toU+10FFFF
. This includes characters in the Basic Multilingual Plane (BMP) range (U+0000
toU+FFFF
) and supplementary characters outside the BMP range (U+10000
toU+10FFFF
).
The ASCII
range is a subset of
UNICODE
range, so a string with
ASCII
repertoire can be converted safely
without loss of information to the character set of any string
with UNICODE
repertoire or to a character set
that is a superset of ASCII
. (All MySQL
character sets are supersets of ASCII
with
the exception of swe7
, which reuses some
punctuation characters for Swedish accented characters.) The use
of repertoire enables character set conversion in expressions
for many cases where MySQL would otherwise return an
“illegal mix of collations” error.
The following discussion provides examples of expressions and their repertoires, and describes how the use of repertoire changes string expression evaluation:
The repertoire for a string constant depends on string content and may differ from the repertoire of the string character set. Consider these statements:
Although the character set is
utf8
in each of the preceding cases, the strings do not actually contain any characters outside the ASCII range, so their repertoire isASCII
rather thanUNICODE
.A column having the
ascii
character set hasASCII
repertoire because of its character set. In the following table,c1
hasASCII
repertoire:The following example illustrates how repertoire enables a result to be determined in a case where an error occurs without repertoire:
- );
Without repertoire, this error occurs:
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (ascii_general_ci,IMPLICIT) for operation 'concat'
Using repertoire, subset to superset (
ascii
tolatin1
) conversion can occur and a result is returned:+---------------+ | CONCAT(c1,c2) | +---------------+ | ab | +---------------+
Functions with one string argument inherit the repertoire of their argument. The result of
UPPER(_utf8'
hasabc
')ASCII
repertoire because its argument hasASCII
repertoire.For functions that return a string but do not have string arguments and use
character_set_connection
as the result character set, the result repertoire isASCII
ifcharacter_set_connection
isascii
, andUNICODE
otherwise:Use of repertoire changes how MySQL evaluates the following example:
Without repertoire, this error occurs:
ERROR 1267 (HY000): Illegal mix of collations (ascii_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat'
With repertoire, a result is returned:
Functions with two or more string arguments use the “widest” argument repertoire for the result repertoire (
UNICODE
is wider thanASCII
). Consider the followingCONCAT()
calls:For the first call, the repertoire is
ASCII
because both arguments are within the range of theascii
character set. For the second call, the repertoire isUNICODE
because the second argument is outside theascii
character set range.The repertoire for function return values is determined based only on the repertoire of the arguments that affect the result's character set and collation.
The result repertoire is
ASCII
because the two string arguments (the second argument and the third argument) both haveASCII
repertoire. The first argument does not matter for the result repertoire, even if the expression uses string values.
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-repertoire.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
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.