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 of a character expression, such as the simple statement SELECT 'string', are defined by the character_set_connection and collation_connection variables.
You can use the COLLATE clause to specify the character set and collation for a character expression. Syntax:
[_charset_name]'string' [COLLATE collation_name]
Sample code:
obclient> SELECT _utf8mb4'abc' COLLATE utf8mb4_unicode_ci;
+------------------------------------------+
| _utf8mb4'abc' COLLATE utf8mb4_unicode_ci |
+------------------------------------------+
| abc |
+------------------------------------------+
1 row in set
Select the character set and collation for a character expression
You can select the character set and collation for a character expression by using the following methods in OceanBase Database:
If you specify both the
_charset_nameandCOLLATE collation_nameparameters, thecharset_namecharacter set andcollation_namecollation are used.If you specify only the
_charset_nameparameter, the specifiedcharset_namecharacter set and the associated default collation are used. To view the default collation for each character set, execute theSHOW CHARACTER SETstatement.If you specify only the
COLLATE collation_nameparameter, the character set specified forcharacter_set_connectionand the default collation specified forcollation collation_nameare used.collation_namemust be a collation supported by the default character set.If neither
CHARACTER SETnorCOLLATEis specified, the character set specified forcharacter_set_connectionand the default collation specified forcollation collation_nameare used.