Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

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. The function returns 0 if the string is empty. It returns NULL if the string is null.

Syntax

ASCII('string')

Argument

string

A CHAR string or a VARCHAR string.

Return type

INTEGER

Examples

To return NULL, use the following example. The NULLIF function returns NULL if the two arguments are the same, so the input argument for the ASCII function is NULL. For more information, see NULLIF function.

SELECT ASCII(NULLIF('','')); +-------+ | ascii | +-------+ | NULL | +-------+

To return the ASCII code 0, use the following example.

SELECT ASCII(''); +-------+ | ascii | +-------+ | 0 | +-------+

To return the ASCII code 97 for the first letter of the word amazon, use the following example.

SELECT ASCII('amazon'); +-------+ | ascii | +-------+ | 97 | +-------+

To return the ASCII code 65 for the first letter of the word Amazon, use the following example.

SELECT ASCII('Amazon'); +-------+ | ascii | +-------+ | 65 | +-------+
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.