MySQL ORD() Function

In MySQL, the ORD() function returns the character code of the first character in a string.

ORD() Syntax

Here is the syntax of MySQL ORD() function:

ORD(string)

Parameters

string
Required. a string.

Return value

In MySQL, the ORD() function returns the character code of the first character in a string.

If the first character is a single-byte character, the ORD() function returns the ASCII value of the character; if the first character is a multi-byte character, return the result of the formula: (1st byte code) + (2nd byte code) * 256 + (3rd byte code) * 256 * 256.

If the parameter is NULL, the function will return NULL.

ORD() Examples

Here are some examples of MySQL ORD() function.

SELECT
    ORD('A'),
    ORD('aa'),
    ORD('B'),
    ORD('bb'),
    ORD('你好'),
    ORD(NULL)\G
     ORD('A'): 65
    ORD('aa'): 97
     ORD('B'): 66
    ORD('bb'): 98
   ORD('你好'): 14990752
    ORD(NULL): NULL
1 row in set (0.00 sec)