MySQL COLLATION() Function
MySQL COLLATION()
function returns the collation of the specified string.
COLLATION()
Syntax
Here is the syntax of the MySQL COLLATION()
function:
COLLATION(str)
Parameters
str
-
Required. A text string.
Return value
The COLLATION()
function returns the collation of the specified string.
The COLLATION()
function will return NULL
if the argument is binary
.
COLLATION()
Examples
The following example shows how to use the COLLATION()
function to get the collation of a string parameter.
SELECT COLLATION('hello');
+--------------------+
| COLLATION('hello') |
+--------------------+
| utf8mb4_0900_ai_ci |
+--------------------+
Let’s look at an example:
SELECT COLLATION(CONVERT('hello' USING latin1));
+------------------------------------------+
| COLLATION(CONVERT('hello' USING latin1)) |
+------------------------------------------+
| latin1_swedish_ci |
+------------------------------------------+
Here, we use the CONVERT()
function to convert the collation of the string 'hello'
to latin1
first, and then use the COLLATION()
function to get the collation of the converted string.
The COLLATION()
function will return NULL
if the argument is binary
.
SELECT COLLATION(NULL);
+-----------------+
| COLLATION(NULL) |
+-----------------+
| binary |
+-----------------+