ASCII function
1. Description
ASCII returns the unsigned integer value of the first byte of the input converted to a string, as an integer. For a string beginning with an ASCII character, this is its ASCII code; subsequent characters do not affect the result.
2. Syntax
ASCII(value)
The Oracle-compatible overloads accept VARCHAR2, NUMBER, BINARY_FLOAT, BINARY_DOUBLE, DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE. Numbers are converted to strings first. Date and time values are formatted using the session’s nls_date_format, nls_timestamp_format, and nls_timestamp_tz_format, respectively, so the result can depend on those settings. A NULL input or an empty converted string returns NULL.
3. Examples
SELECT ascii('abc') FROM dual; -- 97, lowercase a
SELECT ascii('xyz') FROM dual; -- 120, lowercase x
SELECT ascii(321) FROM dual; -- 51, digit character 3
SELECT ascii('') IS NULL FROM dual; -- true
SELECT ascii(to_char('2026-01-01'::date, 'DD-MON-YYYY HH24:MI:SS')) FROM dual; -- 48
4. Non-ASCII characters
For the Oracle-compatible overloads, a non-ASCII character yields the value of its first byte in the database encoding, not its Unicode code point or the value of the complete multibyte character. For example, in a UTF8 database, the first byte of δΈ is hexadecimal E4, or decimal 228. The result depends on the encoding and the overload selected for the call; do not use it to obtain Unicode code points for non-ASCII characters.