Latest Code Tutorials

SQL ASCII() Function: Introduction

SQL ASCII() function is used to return the numeric value of a character given as an input to the function. The ASCII() function acts opposite to that of the CHAR function. ASCII stands for American Standard Code for Information Interchange.


SQL ASCII is a built-in function that accepts a character expression and returns the ASCII code value of the leftmost character of the character expression.


SELECT ASCII (single_character or string);


  1. Single_character: It is a specified character whose numeric value will be returned.
  2. String: If a sequence of characters is inserted in function as input, only the first character, the numeric value, will be returned, ignoring all the remaining characters.


See the following query.

Select Ascii (‘A’);

See the following output.



As the ASCII value of A is 65, it has been returned as output.

See the following query.

Select Ascii (‘a’);

See the output.



As the ASCII value of a is 97, it has been returned as output.

See the following third query.

Select ASCII (‘’);

See the output.



As the above input was a string, only the first character was returned, ignoring all the characters.

Range of ASCII values for characters

A-Z: 65-90

a-z: 97-122

Let’s apply the ASCII function to a table.

Table: Employee

Emp_id Emp_name City State Salary
101 Rohit Raj Patna Bihar 30000
201 Shiva Rana Jalandhar Punjab 20000
301 Karan Kumar Allahabad Uttar Pradesh 40000
401 Suraj Bhakat Kolkata West Bengal 60000
501 Akash Cherukuri Vizag Andhra Pradesh 70000


If we want to print the Numeric Code for the first character of Emp_Name, then the following query has to be considered.


See the following query.

Select Emp_name, ASCII(Emp_name) AS NumCode from Employee;

See the output.

Emp_name NumCode
Rohit Raj 82
Shiva Rana 83
Karan Kumar 75
Suraj Bhakat 83
Akash Cherukuri 65

So, you can see from the output that the Numeric value of the first character is returned under the column name NumCode.

That’s it for this tutorial.

Recommended Posts

SQL Substring()


SQL Replace()

SQL String Functions

SQL Try Catch

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.