Skip to main content
Version: V1.4.1

Character Expressions, Character Sets, and Character Sequences

Each character expression has a character set and collation.

Specify the character set and collation for the CHAR expression​

The character set and collation for the string expression in the SELECT 'string' statement are defined by the character_set_connection and collation_connection system variables.

The COLLATE clause can be used to specify the character set and collation of a character expression. The syntax is as follows:

[_charset_name]'string' [COLLATE collation_name]

For example:

SELECT _utf8mb4'abc' COLLATE utf8mb4_bin;
+----------------------------------+
| _utf8mb4'abc' COLLATE utf8mb4_bin |
+----------------------------------+
| abc |
+----------------------------------+
1 row in set (0.001 sec)

Character set and collation for the character expression​

The seekdb statement selects the character set and collation for a character expression based on the following rules:

  • If you specify both _charset_name and COLLATE collation_name, the character set charset_name and collation collation_name are used.

  • If _charset_name is specified but COLLATE is not, the character set charset_name and its default collation are used. Use the SHOW CHARACTER SET statement to view the default collation for each character set.

  • If no _charset_name is specified but a COLLATE collation_name is specified, the default character set is determined by the value of the character_set_connection system variable and collation collation_name. collation_name must be a collation supported by the default character set.

  • If you do not specify CHARACTER SET or COLLATE, then the default character set is specified by the character_set_connection system variable and collation collation_name.