MySQL 8.1
CHAR(num[, ...] [USING charset])Parameters
- numINT
- Byte code; for Latin letters, digits and punctuation it matches the ASCII code, for example 65 for A
- USING charsetkeywordoptional
- Character set used to read the bytes, for example utf8mb4; without it the result is a binary string
Return value
A binary string of the bytes with the given codes, with USING a string in that character set; NULL arguments are skipped
Examples
String from character codes
MySQL 8.1
SELECT CHAR(72, 105);Skipping NULL among the codes
MySQL 8.1
SELECT CHAR(83, NULL, 81, 76);Cyrillic letter from UTF-8 bytes
MySQL 8.1
SELECT CHAR(208, 191 USING utf8mb4) AS letter;LOWER does not change a binary string
MySQL 8.1
SELECT LOWER(CHAR(72, 105)) AS binary_string,
LOWER(CHAR(72, 105 USING utf8mb4)) AS text_string;Details
Without USING, the result is a binary string (CHARSET(CHAR(72)) returns binary): comparisons with it are byte by byte and case sensitive, and LOWER and UPPER do not change it. To get regular text, give a character set: CHAR(72, 105 USING utf8mb4).
Each code sets a byte, not a character: a Cyrillic letter takes two bytes in utf8mb4, so «п» is CHAR(208, 191 USING utf8mb4). A code greater than 255 is written as several bytes: CHAR(256) equals CHAR(1, 0).