CHR function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

CHR function

The CHR function returns the character that matches the ASCII code point value specified by the input parameter.

Syntax

CHR(number)

Argument

number

The input parameter is an INTEGER that represents an ASCII code point value.

Return type

CHAR

The CHR function returns a CHAR string if an ASCII character matches the input value. If the input number has no ASCII match, the function returns NULL.

Examples

To return the character that corresponds with ASCII code point 0, use the following example. Note that the CHR function returns NULL for the input 0.

SELECT CHR(0); +-----+ | chr | +-----+ | | +-----+

To return the character that corresponds with ASCII code point 65, use the following example.

SELECT CHR(65); +-----+ | chr | +-----+ | A | +-----+

To return distinct event names that begin with a capital A (ASCII code point 65), use the following example. The following example uses the EVENT table from the TICKIT sample database. For more information, see Sample database.

SELECT DISTINCT eventname FROM event WHERE SUBSTRING(eventname, 1, 1)=CHR(65) LIMIT 5; +-----------------------+ | eventname | +-----------------------+ | A Catered Affair | | As You Like It | | A Man For All Seasons | | Alan Jackson | | Armando Manzanero | +-----------------------+