SQL CHR

The SQL CHR function accepts an ASCII code and returns the corresponding character. The CHR function is the opposite of the ASCII function.

Syntax

CHR(ascii)Code language: SQL (Structured Query Language) (sql)

Most RDBMS such as Microsoft SQL Server, PostgreSQL, and Oracle uses the CHR function except MySQL uses the CHAR function which is equivalent to the CHR function.

Arguments

ascii
The ASCII code that is in the range (1,255)

Return Type

A character that represents the input ASCII code.

The function returns NULL if the input number is NULL.

If the input number is out of the range (1,255), the RDMBS may issue an error. This behavior is specific to the implementation of the CHR function in each RDBMS.

Examples

The following statement returns characters of the ASCII code 65 and 97:

SELECT CHR(65), CHR(97);
Code language: SQL (Structured Query Language) (sql)
 chr | chr
-----+-----
 A   | a
(1 row)Code language: SQL (Structured Query Language) (sql)
Was this tutorial helpful ?