Skip to content

CHR

Returns a character represented by expr's binary equivalent as a STRING value. If expr is invalid, an error is returned.

Syntax

sql
CHR(expr [USING NCHAR_CS])

Arguments

expr: Numeric value representing a character in the corresponding character set.


USING NCHAR_CS (optional): This argument specifies that the national character set is used for the return value. If USING NCHAR_CS is omitted, the current database character set is used.

Return Values

A STRING value in UTF-8 encoding is returned.

Usage Notes

  • For single-byte character sets, if expr is greater than 256, the database returns the binary value of expr mod 256. This means the remainder of the division by 256. Example: CHR(33) = '!' because 33 mod 256 = 33.
  • For multi-byte character sets, expr must refer to a complete code point. Invalid code points are not validated, and the result is undefined. Concatenation of multiple bytes is not supported.

Example

sql
select  chr(42), 
        chr(42 USING NCHAR_CS), 
        chr(342), 
        chr(342 USING NCHAR_CS), 
        chr(937),                      
        chr(937 USING NCHAR_CS);
+---------+------------------------+----------+-------------------------+----------+-------------------------+
| CHR(42) | CHR(42 USING NCHAR_CS) | CHR(342) | CHR(342 USING NCHAR_CS) | CHR(937) | CHR(937 USING NCHAR_CS) |
+---------+------------------------+----------+-------------------------+----------+-------------------------+
| *       | *                      | V        | Ŗ                       | ©        | Ω                       |
+---------+------------------------+----------+-------------------------+----------+-------------------------+