CHARSET | Syntax: | CHARSET(String) | Return value: | CHAR | Function type: | Information function | |
|
|
The CHARSET() function returns the character set of the argument "String".
The return value is the name 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 CHARSET() function also returns binary. |
SQL Examples for the CHARSET function |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
SELECT charset('Test');
SELECT charset(100);
SELECT CHARSET(convert(100.234 USING utf8));
SELECT CHARSET(convert(100 USING utf8));
SELECT CHARSET(convert('Test' USING utf32));
SELECT CHARSET(convert('Test', char));
SELECT CHARSET(convert('Test', nchar)); /* To National Character Set */
SELECT CHARSET(convert('Test', char CHARACTER SET utf8mb4));
SELECT CHARSET(null);
|
|
charset('Test') |
varchar(64) BINARY |
binary |
|
|
charset(100) |
varchar(64) BINARY |
binary |
|
|
CHARSET(convert(100.234 USING utf8)) |
varchar(64) BINARY |
utf8 |
|
|
CHARSET(convert(100 USING utf8)) |
varchar(64) BINARY |
utf8 |
|
|
CHARSET(convert('Test' USING utf32)) |
varchar(64) BINARY |
utf32 |
|
|
CHARSET(convert('Test', char)) |
varchar(64) BINARY |
binary |
|
|
CHARSET(convert('Test', nchar)) |
varchar(64) BINARY |
utf8 |
|
|
CHARSET(convert('Test', char CHARACTER SET utf8mb4)) |
varchar(64) BINARY |
utf8mb4 |
|
|
CHARSET(null) |
varchar(64) BINARY |
binary |
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the CHARSET() function in MySQL and MariaDB databases |
In MySQL and MariaDB the CHARSET() function is used to get the character set of a specific character string or of a given expression by having the function return the character set 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 character set of a character string or an expression can be identified dynamically, 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 |
|