How to use the MySQL ASCII() function
The ASCII() function in MySQL returns the ASCII code value of the leftmost character of a string. It can be used to get the ASCII value of alphanumeric and other characters.
On this page
The ASCII() function in MySQL returns the ASCII code value of the leftmost character of a string. It can be used to get the ASCII value of alphanumeric and other characters.
Syntax
The syntax for ASCII() is:
ASCII(string)
Where string is the string to get the ASCII value from.
Examples
-
Get ASCII value of a letter:
SELECT ASCII('A');This returns 65, which is the ASCII code for uppercase letter ‘A’.
-
Get ASCII value of a number:
SELECT ASCII('4');This returns 52, the ASCII code for character ‘4’.
-
Get ASCII code for a special character:
SELECT ASCII('$');This returns 36, the ASCII code for dollar symbol ‘$’.
-
Get ASCII value from a string:
SELECT ASCII('Hello');This returns 72, the ASCII value for ‘H’, the leftmost character.
-
Get ASCII value of a lowercase letter:
SELECT ASCII('q');This returns 113, the ASCII code for lowercase ‘q’.
Other Similar Functions
Other ASCII-related functions in MySQL:
ORD()- Same asASCII()CHAR()- Return character for ASCII valueCONCAT()- Concatenate stringsINSERT()- Insert substring into string
So ASCII() provides a simple way to get the numeric ASCII code of characters in strings in MySQL.