Syntax
COERCIBILITY(str)
Purpose
Returns the priority of the collation of the string str during multibyte sorting.
When comparing two variables with the same character set, the collation is used as the rule. However, when comparing two variables with different character sets, the priority between different character sets needs to be specified. For example, the following statement:
obclient> SELECT c1 FROM t WHERE c1 = 'Y';
If c1 and 'Y' use the same collation, there is no ambiguity. However, if the table t specifies a different collation in table_option or the system variable collation_connection uses a different collation, the collation used during comparison depends on the priority between the two collations.
The priorities of different collations are shown in the table below, with smaller values indicating higher priority.
| Value | Description | Examples |
|---|---|---|
| 0 | Explicitly specified collation | Explicit COLLATE clause. |
| 1 | No collation | Concatenation of strings with different collations. |
| 2 | Implicitly specified collation | Column values, system parameters, or variables. |
| 3 | System constant | Return values of system functions such as the USER() function. |
| 4 | Coercible value | Literal strings. |
| 5 | Numeric value | Numeric or time values. |
| 6 | Ignorable value | NULL or expressions that evaluate to NULL. |
OceanBase Database resolves ambiguities using the coercibility values and the following rules:
A smaller coercibility value indicates a higher priority.
If the collations of the two operands have the same coercibility, the following additional rules are used:
If both character sets are Unicode or neither is Unicode, and the collations are different, an error is returned.
If one character set is Unicode and the other is not, the Unicode character set has higher priority. For example, the following statement does not return an error:
obclient> SELECT CONCAT(t1.utf8_column, t2.gbk_column) FROM t1,t2;For the same character set, if the collations are
_binanda_cior_cs, the_bincollation is used.
Examples
obclient> SELECT COERCIBILITY('oceanbase' COLLATE utf8mb4_bin);
+-----------------------------------------------+
| COERCIBILITY('oceanbase' COLLATE utf8mb4_bin) |
+-----------------------------------------------+
| 0 |
+-----------------------------------------------+
1 row in set
obclient> SELECT COERCIBILITY('oceanbase');
+---------------------------+
| COERCIBILITY('oceanbase') |
+---------------------------+
| 4 |
+---------------------------+
1 row in set
obclient> SELECT COERCIBILITY(user());
+----------------------+
| COERCIBILITY(user()) |
+----------------------+
| 3 |
+----------------------+
1 row in set
obclient> SELECT COERCIBILITY(1000);
+--------------------+
| COERCIBILITY(1000) |
+--------------------+
| 5 |
+--------------------+
1 row in set
