Oracle String/Char Function - Oracle/PLSQL ASCII Function






This Oracle tutorial shows how to use the Oracle/PLSQL ASCII function.

Oracle/PLSQL ASCII function gives the ASCII value of the first character of a string.

The Oracle/PLSQL ASCII function returns the NUMBER code that represents the specified character.

Syntax

The syntax for the Oracle/PLSQL ASCII function is:

ASCII( single_character )

ASCII converts single_character the character to the NUMBER code.

If more than one character is provided, the ASCII function will return the value for the first character and ignore all of the characters after the first.

Example

SQL> SELECT ASCII('abc') FROM dual;

ASCII('ABC')
------------
          97

SQL>

ASCII('t')
----------
       116
 
ASCII('T')
----------
        84
 
ASCII('T2')
----------
        84

ASCII(x) gets the ASCII value for the character x. The following query gets the ASCII value of a, A, 0, and 9 using ASCII():


SQL> SELECT ASCII('a'), ASCII('A'), ASCII(0), ASCII(9) FROM dual;

ASCII('A') ASCII('A')   ASCII(0)   ASCII(9)
---------- ---------- ---------- ----------
        97         65         48         57

SQL>