Specifying Character Sets and Collations
774
Examples:
SELECT _latin1 x'AABBCC';
SELECT _latin1 0xAABBCC;
SELECT _latin1 b'1100011';
SELECT _latin1 0b1100011;
MySQL determines a literal's character set and collation in the following manner:
• If both
_X
and
COLLATE Y
are specified, character set
X
and collation
Y
are used.
• If
_X
is specified but
COLLATE
is not specified, character set
X
and its default collation are used. To
see the default collation for each character set, use the
SHOW COLLATION
statement.
• Otherwise, the character set and collation given by the
character_set_connection
[442]
and
collation_connection
[443]
system variables are used.
Examples:
• A string with
latin1
character set and
latin1_german1_ci
collation:
SELECT _latin1'Müller' COLLATE latin1_german1_ci;
• A string with
latin1
character set and its default collation (that is,
latin1_swedish_ci
):
SELECT _latin1'Müller';
• A string with the connection default character set and collation:
SELECT 'Müller';
Character set introducers and the
COLLATE
clause are implemented according to standard SQL
specifications.
An introducer indicates the character set for the following string, but does not change now how the
parser performs escape processing within the string. Escapes are always interpreted by the parser
according to the character set given by
character_set_connection
[442]
.
The following examples show that escape processing occurs using
character_set_connection
[442]
even in the presence of an introducer. The examples use
SET NAMES
(which changes
character_set_connection
[442]
, as discussed in
Section 10.1.4,
“Connection Character Sets and Collations”
), and display the resulting strings using the
HEX()
[889]
function so that the exact string contents can be seen.
Example 1:
mysql>
SET NAMES latin1;
Query OK, 0 rows affected (0.01 sec)
mysql>
SELECT HEX('à\n'), HEX(_sjis'à\n');
+------------+-----------------+
| HEX('à\n') | HEX(_sjis'à\n') |
+------------+-----------------+
| E00A | E00A |
+------------+-----------------+
1 row in set (0.00 sec)
Here, “
à
” (hex value
E0
) is followed by “
\n
”, the escape sequence for newline. The escape sequence
is interpreted using the
character_set_connection
[442]
value of
latin1
to produce a literal
newline (hex value
0A
). This happens even for the second string. That is, the introducer of
_sjis
does
not affect the parser's escape processing.
Example 2:
mysql>
SET NAMES sjis;
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...