SQL Tutorial

SQL CHAR or CHR Function

SQL CHAR or CHR function is the opposite of ASCII. It converts an integer in range 0-255 into a ascii character. Here are syntaxes:

CHAR(expression)
CHR(expression)

In this query, we convert 65 and 97 into ASCII character using SQL CHAR function:

SELECT CHAR(65) AS ch_65,
	   CHAR(97) AS ch_97

Here is the output:

ch_65   ch_97 
------  ------
A       a     

Microsoft SQL Server, Sybase, and MySQL use CHAR() function while other RDBMSs use CHR function. You can take a look at the documentation to identify which one is used.

Read On