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

MySQLMySQLi Database

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)
raja
Published on 19-Feb-2018 13:07:55
Advertisements