SQL Tutorial SQL Advanced SQL Database SQL References

Oracle ASCII() Function



The Oracle (PL/SQL) ASCII() function returns the ASCII value of specified character. If a string is entered, the function returns the ASCII value for the first character of the string only.

Syntax

ASCII(character)

Parameters

character Required. Specify the character to return the ASCII value for. If more than one character is entered, the function will only return the value for the first character.

Return Value

Returns the ASCII value of a character.

Example 1:

The example below shows the usage of ASCII() function.

ASCII('A')
Result: 65

ASCII(1)
Result: 49

ASCII('AlphaCodingSkills.com')
Result: 65

ASCII(123)
Result: 49

ASCII('@gmail.com')
Result: 64

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCity
1JohnLondon
2MarryNew York
3JoParis
4KimAmsterdam
5RameshNew Delhi
6HuangBeijing

In the query below, the ASCII() function is used to get the ASCII value of first character of Name column value of Employee table.

SELECT Employee.*, ASCII(Name) AS ASCII_Val FROM Employee;

This will produce the result as shown below:

EmpIDNameCityASCII_Val
1JohnLondon74
2MarryNew York77
3JoParis74
4KimAmsterdam75
5RameshNew Delhi82
6HuangBeijing72

❮ Oracle Functions

5