Each character expression has a character set and a character order.
Specify the character set and collation of the character expression
For a simple statement SELECT 'string', the character set and collation for the string are determined 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:
obclient> SELECT _utf8mb4'abc' COLLATE utf8mb4_unicode_ci;
+------------------------------------------+
| _utf8mb4'abc' COLLATE utf8mb4_unicode_ci |
+------------------------------------------+
| abc |
+------------------------------------------+
1 row in set
The gb18030_2022 character set is supported. For more information, see the following statements: - To convert a hexadecimal number to the corresponding character in the gb18030_2022 character set, add the _gb18030_2022 prefix before the hexadecimal number. - To specify a string in the gb18030_2022 character set, add the _gb18030_2022 prefix before the string.
obclient> SELECT _gb18030_2022 0xCDE5 AS c FROM DUAL;
+-----+
| c |
+-----+
| Bay |
+-----+
1 row in set
obclient> SELECT _gb18030_2022 'bay' AS c FROM DUAL;
+-----+
| c |
+-----+
| Bay |
+-----+
1 row in set
Choose the character set and collation of a character expression
OceanBase Database determines the character set and collation for a character expression in the following ways:
If both the
_charset_nameoption and theCOLLATE collation_nameclause are specified, the character setcharset_nameand the collationcollation_nameare used.If only
CHARSETis specified withoutCOLLATE, the character setcharset_nameand its default collation are used. To view the default collation for each character set, use theSHOW CHARACTER SETstatement.If
_charset_nameis not specified butCOLLATE collation_nameis, the default character set is specified by thecharacter_set_connectionsystem variable and theCOLLATE collation_nameclause.collation_namemust be a collation supported by the default character set.If neither
CHARACTER SETnorCOLLATEare specified, the default character set is determined by thecharacter_set_connectionsystem variable andcollation collation_name.