What are the similarities and differences between MySQL ORD() and ASCII() functions?

MySQLMySQLi Database

MySQL ORD() function returns the code for the leftmost character if that character is a multi-byte i.e. sequence of one or more bytes, with the help of the following formula

(1st bytecode) + (2nd bytecode * 256) + (3rd bytecode * 256^2)

On the other hand, ASCII() function returns the ASCII value of the leftmost character of a given string.

The difference between them lies on the point that whether the leftmost character is a multi-byte character or not. If it is not a multi-byte character then both ORD() and ASCII() functions return similar results. Following example will demonstrate it.

mysql> Select ORD('Tutorialspoint');
+-----------------------+
| ORD('Tutorialspoint') |
+-----------------------+
|                    84 |
+-----------------------+
1 row in set (0.00 sec)

mysql> Select ASCII('Tutorialspoint');
+-------------------------+
| ASCII('Tutorialspoint') |
+-------------------------+
|                      84 |
+-------------------------+
1 row in set (0.00 sec)
raja
Published on 20-Feb-2018 14:50:43
Advertisements