MySQL ASCII function is one of the String Function, which returns the ASCII code of the left most character of a character expression. In this article we will show you, How to use this string ASCII in MySQL with example.
MySQL ASCII Syntax
The basic syntax of the ASCII Function in MySQL is as shown below:
SELECT ASCII (Expression) FROM [Source]
Expression: Please specify a valid Expression for which you want to find the ASCII code. If the specified expression is more than one character then, MySQL ASCII Function will return the ASCII code of a left most character of the expression.
TIP: Please refer ASCII Table to check the ASCII values for each and every character.
In order to demonstrate this string function, We are going to use the customerdetails table data that we shown below
MySQL ASCII Example 1
The ASCII Function in MySQL is used to return the ASCII code of the leftmost character in an expression. The following query will show multiple ways to use this function.
SELECT ASCII('A'); SELECT ASCII(1); SELECT ASCII('abcd'); SELECT ASCII(''); SELECT ASCII(NULL);
MySQL ASCII Function Example 2
In this example, we are going to implement the string ASCII function in MySQL on different columns in a table. Following statement will return the ASCII code of leftmost character in First_Name, Last_Name, and Yearly_Income column.
-- MySQL String ASCII Example USE company; SELECT First_Name, ASCII(First_Name) AS ASCII_FName, Last_Name, ASCII(Last_Name) AS ASCII_LName, Education, Profession, Yearly_Income, ASCII(Yearly_Income) AS ASCII_Income, Sales FROM customerdetails;
From the below screenshot you can observe that, 84 is the ASCII code of T, and 57 is the ASCII code of 9
Thank You for Visiting Our Blog