MySQL ASCII() Function

In MySQL, the ASCII() function returns the corresponding ASCII value of the specified character. ASCII() only returns the ASCII value of the first character of the specified string.

ASCII() Syntax

Here is the syntax of the MySQL ASCII() function:

ASCII(character)

Parameters

character
Required. The character whose ASCII value will be returned. If there are more than one characters, it will only return the ASCII value of the first character.

Return value

The function ASCII() returns the ASCII value of the given character. It will return NULL returns the ASCII value of the given character. It will return character returns the ASCII value of the given character. It will return NULL.

ASCII() Examples

To return the ASCII value of A, use the following statement:

SELECT ASCII('A');
+------------+
| ASCII('A') |
+------------+
|         65 |
+------------+

If the argument is more than one character, only the ASCII value of the first character is returned:

SELECT ASCII('BA');
+-------------+
| ASCII('BA') |
+-------------+
|          66 |
+-------------+

Here, although the argument is BA, but only returned the ASCII value of B: 66.