The MySQL string ORD function is one of the String Function, which is to find the code of the leftmost character in a string.
- If the leftmost character is multibyte, the ORD function uses the formula to calculate the code: (1st-byte code) + (2nd-byte code *256) + (3rd-byte code * 256^2)….
- If the leftmost character is not a multibyte character, this MySQL string ORD function writes the ASCII code of that byte.
MySQL String ORD Syntax
The basic syntax of the ORD string in MySQL is as shown below.
MySQL ORD Function Example
The following query shows multiple ways to use this MySQL String ORD function. Here, we used only single characters; that’s why this function returns the ASCII values of those characters.
Within the first two statements, we used multiple values. However, this function returns the ASCII value of the first character.
In the third statement, we used a different character. So, it used the formula to get that code.