COLLATION | Syntax: | COLLATION(String) | Return value: | CHAR | Function type: | Information function | |
|
|
The COLLATION() function returns the collation of the argument "String".
The return value is the name of the collation of the character set.
If the "String" argument is not a string, it is treated as a binary string and the function returns binary.
If the value of the argument is NULL, the COLLATION() function also returns binary. |
SQL Examples for the COLLATION function |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
SELECT collation('Test');
SELECT collation(100);
SELECT collation(convert(100.234 USING utf8));
SELECT collation(convert(100 USING utf8));
SELECT collation(convert('Test' USING utf32));
SELECT collation(convert('Test', char));
SELECT collation(convert('Test', nchar)); /* To National Character Set */
SELECT collation(convert('Test', char CHARACTER SET utf8mb4));
SELECT collation(null);
|
|
collation('Test') |
varchar(64) BINARY |
binary |
|
|
collation(100) |
varchar(64) BINARY |
binary |
|
|
collation(convert(100.234 USING utf8)) |
varchar(64) BINARY |
utf8_general_ci |
|
|
collation(convert(100 USING utf8)) |
varchar(64) BINARY |
utf8_general_ci |
|
|
collation(convert('Test' USING utf32)) |
varchar(64) BINARY |
utf32_general_ci |
|
|
collation(convert('Test', char)) |
varchar(64) BINARY |
binary |
|
|
collation(convert('Test', nchar)) |
varchar(64) BINARY |
utf8_general_ci |
|
|
collation(convert('Test', char CHARACTER SET utf8mb4)) |
varchar(64) BINARY |
utf8mb4_general_ci |
|
|
collation(null) |
varchar(64) BINARY |
binary |
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the COLLATION() function in MySQL and MariaDB databases |
In MySQL and MariaDB the COLLATION() function is used to retrieve the collation of a specific string or expression by returning the collation name as a string. The argument can be a table column name, a literal string, or any valid expression that evaluates to a string. Thus, the collation of a character string or an expression can be dynamically identified, for example in data analysis, data manipulation or when dealing with multilingual data. The function is based on the sorting and character set settings of the server, the database and the table column. |
|
Further MySQL und MariaDB SQL Information functions |
|