Every character expression has a character set and a collation.
Specify the character set and collation for a character expression
The default character set and collation for the character expression in a simple statement such as SELECT 'string' are defined by the character_set_connection and collation_connection system variables.
You can use the COLLATE clause to specify the character set and collation for a character expression, with the following syntax:
[_charset_name]'string' [COLLATE collation_name]
Example:
obclient> SELECT _utf8mb4'abc' COLLATE utf8mb4_unicode_ci;
+------------------------------------------+
| _utf8mb4'abc' COLLATE utf8mb4_unicode_ci |
+------------------------------------------+
| abc |
+------------------------------------------+
1 row in set
You can prepend the hexadecimal value with the _gb18030_2022 prefix in SQL statements to convert the value to the corresponding character based on the gb18030_2022 encoding. You can also prepend the string with the _gb18030_2022 prefix in SQL statements to specify that the string is based on the gb18030_2022 encoding.
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
Character set and collation of character expressions
OceanBase Database selects the character set and collation for a character expression as follows:
If both
_charset_nameandCOLLATE collation_nameare specified, thecharset_namecharacter set and thecollation_namecollation are used.If
_charset_nameis specified butCOLLATEis not specified, the character setcharset_nameand its default collation are used. Use theSHOW CHARACTER SETstatement to see the default collation for each character set.If
_charset_nameis not specified butCOLLATE collation_nameis specified, the default character set is determined by the value of thecharacter_set_connectionsystem variable and the collation specified bycollation_name.collation_namemust be a collation supported by the default character set.If you do not specify either
CHARACTER SETorCOLLATE, the default character set is determined by thecharacter_set_connectionsystem variable andcollation collation_name.