Oracle ASCII

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 the character_expression.
  • If the character_expression consists of more than one character, the ASCII() function will return the ASCII code of the first character only.
  • The ASCII() function returns NULL if the character_expresion is NULL.

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)
Oracle ASCII function example

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)
Oracle ASCII function string example

The following illustrates how the ASCII() function handles NULL.

SELECT
  ASCII( NULL )
FROM
  dual;Code language: SQL (Structured Query Language) (sql)
Oracle ASCII function - null example

In this example, the ASCII() function returns NULLas 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.

Was this tutorial helpful?