Character String Literal Character Set and Collation
Every character string literal has a character set and a collation.
For the simple statement SELECT '
, the string has the connection default character set and collation defined by the string
'character_set_connection
and collation_connection
system variables.
A character string literal may have an optional character set introducer and COLLATE
clause, to designate it as a string that uses a particular character set and collation:
[_charset_name]'string' [COLLATE collation_name]
The _
expression is formally called an introducer. It tells the parser, “the string that follows uses character set charset_name
charset_name
.” An introducer does not change the string to the introducer character set like CONVERT()
would do. It does not change the string value, although padding may occur. The introducer is just a signal. See Section 10.3.8, “Character Set Introducers”.
Examples:
SELECT 'abc';
SELECT _latin1'abc';
SELECT _binary'abc';
SELECT _utf8'abc' COLLATE utf8_danish_ci;
Character set introducers and the COLLATE
clause are implemented according to standard SQL specifications.
MySQL determines the character set and collation of a character string literal in the following manner:
-
If both
_charset_name
andCOLLATE
are specified, character setcollation_name
charset_name
and collationcollation_name
are used.collation_name
must be a permitted collation forcharset_name
. -
If
_charset_name
is specified butCOLLATE
is not specified, character setcharset_name
and its default collation are used. To see the default collation for each character set, use theSHOW CHARACTER SET
statement or query theINFORMATION_SCHEMA
CHARACTER_SETS
table. -
If
_charset_name
is not specified butCOLLATE
is specified, the connection default character set given by thecollation_name
character_set_connection
system variable and collationcollation_name
are used.collation_name
must be a permitted collation for the connection default character set. -
Otherwise (neither
_charset_name
norCOLLATE
is specified), the connection default character set and collation given by thecollation_name
character_set_connection
andcollation_connection
system variables are used.Every character string literal has a character set and a collation.
For the simple statement
SELECT '
, the string has the connection default character set and collation defined by thestring
'character_set_connection
andcollation_connection
system variables.A character string literal may have an optional character set introducer and
COLLATE
clause, to designate it as a string that uses a particular character set and collation:[_charset_name]'string' [COLLATE collation_name]
The
_
expression is formally called an introducer. It tells the parser, “the string that follows uses character setcharset_name
charset_name
.” An introducer does not change the string to the introducer character set likeCONVERT()
would do. It does not change the string value, although padding may occur. The introducer is just a signal. See Section 10.3.8, “Character Set Introducers”.Examples:
SELECT 'abc'; SELECT _latin1'abc'; SELECT _binary'abc'; SELECT _utf8'abc' COLLATE utf8_danish_ci;
Character set introducers and the
COLLATE
clause are implemented according to standard SQL specifications.MySQL determines the character set and collation of a character string literal in the following manner:
-
If both
_charset_name
andCOLLATE
are specified, character setcollation_name
charset_name
and collationcollation_name
are used.collation_name
must be a permitted collation forcharset_name
. -
If
_charset_name
is specified butCOLLATE
is not specified, character setcharset_name
and its default collation are used. To see the default collation for each character set, use theSHOW CHARACTER SET
statement or query theINFORMATION_SCHEMA
CHARACTER_SETS
table. -
If
_charset_name
is not specified butCOLLATE
is specified, the connection default character set given by thecollation_name
character_set_connection
system variable and collationcollation_name
are used.collation_name
must be a permitted collation for the connection default character set. -
Otherwise (neither
_charset_name
norCOLLATE
is specified), the connection default character set and collation given by thecollation_name
character_set_connection
andcollation_connection
system variables are used.
-
- 点赞
- 收藏
- 关注作者
评论(0)