MySQL 8.1
CHAR(num[, ...] [USING charset])- [ ]optional part
- ...can be repeated
- num
- Byte value; a number greater than 255 gives several bytesINT
- USING charset
- Read the bytes as a string in the given character set; without USING, a binary stringOptional
- charset
- Character set, for example utf8mb4Keywordarmscii8asciibig5binarycp1250cp1251cp1256cp1257cp850cp852cp866cp932dec8eucjpmseuckrgb18030gb2312gbkgeostd8greekhebrewhp8keybcs2koi8rkoi8ulatin1latin2latin5latin7maccemacromansjisswe7tis620ucs2ujisutf16utf16leutf32utf8mb3utf8mb4
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).
For Latin letters, digits and punctuation the code matches the ASCII code, for example 65 is A. 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).