CHAR
Description
The CHAR function interprets each argument as an integer and returns a string consisting of the characters represented by those integer code values.
Syntax
CHAR(<expr>[, <expr> ...] [USING <charset_name>])
Parameters
| Parameter | Description |
|---|---|
<expr> | Integer code value to be converted to a character. Type: INT |
Return Value
Returns VARCHAR type, a string composed of characters corresponding to the argument integer code values.
Special cases:
- If any argument is NULL, returns an empty string
- If the result string is illegal for the given character set, returns NULL
- Arguments greater than 255 are converted to multi-byte characters. For example,
CHAR(15049882)is equivalent toCHAR(229, 164, 154)
Examples
- Basic usage: ASCII character generation
SELECT CHAR(68, 111, 114, 105, 115);
+--------------------------------------+
| char('utf8', 68, 111, 114, 105, 115) |
+--------------------------------------+
| Doris |
+--------------------------------------+
- Multi-byte UTF-8 characters (Chinese)
SELECT CHAR(15049882, 15179199, 14989469);
+--------------------------------------------+
| char('utf8', 15049882, 15179199, 14989469) |
+--------------------------------------------+
| 多睿丝 |
+--------------------------------------------+
- Illegal character returns NULL
SELECT CHAR(255);
+-------------------+
| char('utf8', 255) |
+-------------------+
| NULL |
+-------------------+
- NULL value handling
SELECT CHAR(NULL);
+------------+
| CHAR(NULL) |
+------------+
| |
+------------+