What function in MySQL can be used to get the number code of a specific character?


String function ASCII() in MySQL returns the ASCII number code of the specific character.

Syntax

ASCII(str)

Here, str, the argument of ASCII() function, is the string whose ASCII value of the first character to be retrieved.

It is pertinent to mention here that it will return the number code the left the most character i.e. first character of the string given as argument.

Example

mysql> SELECT ASCII('A') as 'ASCII VALUE OF CAPITAL A';
+--------------------------+
| ASCII VALUE OF CAPITAL A |
+--------------------------+
| 65                       |
+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT ASCII('a') as 'ASCII VALUE OF CAPITAL a';
+--------------------------+
| ASCII VALUE OF CAPITAL a |
+--------------------------+
| 97                       |
+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT ASCII('Abhay') as 'Left_most Character ASCII value';
+---------------------------------+
| Left_most Character ASCII value |
+---------------------------------+
| 65                              |
+---------------------------------+
1 row in set (0.00 sec)

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements