The Oracle ASCII
function returns an ASCII code value of a character or character expression.
Syntax
ASCII(character_expression)
Code language: SQL (Structured Query Language) (sql)
Arguments
The ASCII()
function accepts one argument:
- character_expression is a character or character expression.
Return values
- The
ASCII()
function returns an integer that represents the ASCII code value of thecharacter_expression
. - If the
character_expression
consists of more than one character, theASCII()
function will return the ASCII code of the first character only. - The
ASCII()
function returnsNULL
if thecharacter_expresion
isNULL
.
Examples
The following statement returns character code value of characters A, B, and C:
SELECT
ASCII( 'A' ),
ASCII( 'B' ),
ASCII( 'C' )
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
If you pass the ABC
string to the ASCII()
function, it will return only the ASCII code of the first character as shown in the following example:
SELECT
ASCII( 'ABC' )
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
The following illustrates how the ASCII()
function handles NULL
.
SELECT
ASCII( NULL )
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
In this example, the ASCII()
function returns NULL
as we expected.
Remarks
Noted that ASCII stands for American Standard Code for Information Interchange, which is a character encoding standard. For more information on ASCII characters, see the ASCII page on Wikipedia.
In this tutorial, you have learned how to use the Oracle ASCII()
function to ASCII code value of the character or character expression.