ASCII function - Amazon Redshift

ASCII function

The ASCII function returns the ASCII code, or the Unicode code-point, of the first character in the string that you specify.

Syntax

ASCII(string)

Argument

string

You specify a CHAR or VARCHAR string for whose first character you want the ASCII code or Unicode code-point.

Return type

The ASCII function returns an INTEGER value with the ASCII code or Unicode code-point of the first character of the string that you specify. The function returns 0 if the string is empty. It returns null if the string is null.

Examples

The following example returns the ASCII code 97 for the first letter of the word amazon.

select ascii('amazon');

This example returns the following output.

ascii ------- 97

The following example returns the ASCII code 65 for the first letter of the word Amazon.

select ascii('Amazon');

This example returns the following output.

ascii ------- 65