MySQL String ORD Function

The MySQL string ORD function is one of the MySQL String Functions, 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.



MySQL String ORD Function 1

Within the first two statements, we used multiple values. However, this MySQL function returns the ASCII code value of the first character. In the third statement, we used a different character. So, this String method used the formula to get that code.


SELECT ORD('213');

MySQL ORD Function 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.