©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The COLLATION SQL Function in MySQL and MariaDB - Collation of the argument

COLLATIONSyntax:COLLATION(String)
Return value:CHAR
Function type:Information function
Function Description

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: Download

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.
CHRCOALESCECOERCIBILITYCOLLATIONCOMPRESSCONCATCONCAT_WS

Further MySQL und MariaDB SQL Information functions

BENCHMARKBENCHMARK(Number, Expression)
More about BENCHMARK Function

BINLOG_GTID_POSBINLOG_GTID_POS()

CHARSETCHARSET(String)
More about CHARSET Function

COERCIBILITYCOERCIBILITY(String)
More about COERCIBILITY Function

CONNECTION_IDCONNECTION_ID()
More about CONNECTION_ID Function

CURRENT_USERCURRENT_USER()
More about CURRENT_USER Function

CURRENT_ROLECURRENT_ROLE()
More about CURRENT_ROLE Function

DATABASEDATABASE()
More about DATABASE Function

DECODE_HISTOGRAMDECODE_HISTOGRAM()

DEFAULTDEFAULT(Column)
More about DEFAULT Function

FOUND_ROWSFOUND_ROWS()
More about FOUND_ROWS Function

LAST_INSERT_IDLAST_INSERT_ID([Expression])
More about LAST_INSERT_ID Function

LAST_VALUELAST_VALUE(Expression [, Expression ...])
More about LAST_VALUE Function

ROWNUMROWNUM()

ROW_COUNTROW_COUNT()
More about ROW_COUNT Function

SCHEMASCHEMA()
More about SCHEMA Function

SESSION_USERSESSION_USER()
More about SESSION_USER Function

SYSTEM_USERSYSTEM_USER()
More about SYSTEM_USER Function

USERUSER()
More about USER Function

VERSIONVERSION()
More about VERSION Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the COLLATION SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer