Open In App

ASCII() Function in MySQL

Last Updated : 08 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to cover the ASCII function with examples and you will see the ASCII MYSQL query. And will also cover the ASCII code for the given character. Let’s discuss one by one.

ASCII function in MySQL is used to find the ASCII code of the leftmost character of a character expression.

Syntax :

ASCII(str)

Parameter :

This method accepts one parameter as mentioned above in the syntax and described below in the example.

  • str – A string whose ASCII value of the leftmost character is to be retrieved.

Returns :

It returns the ASCII code of the leftmost character. It also returns 0 If the string is empty and NULL if the string is NULL.

Example-1 :

ASCII() function to check the value for a lowercase character.

SELECT ASCII('g')AS Lower_Case;

Output :

Lower_Case
103

Example-2 :

ASCII() function to check the value for a uppercase character.

SELECT ASCII('G')AS Upper_Case;

Output :

Upper_Case 
71

Example-3 :

ASCII() function to check the value for a input string.

SELECT ASCII('MySQL')AS String_Value;

Output :

String_Value
77

Example-4 :

ASCII() function to check the value for every input string in a column under a table.

Table -Student_Details

Student_Id  Student_Name
101 Tina
102 Rohit
103 Aman
103 Sneha
SELECT ASCII(Student_Name)  AS Ascii_Name FROM Student_Details ;

Ascii_Name
84
82
65
83

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads