MySQL ORD() function
ORD() function
MySQL ORD() function returns the code for the leftmost character if that character is a multi-byte (sequence of one or more bytes) one. If the leftmost character is not a multi-byte character, ORD() returns the same value as the ASCII() function.
The formula to calculate the numeric values of its constituent bytes is :
(1st byte code) + (2nd byte code * 256) + (3rd byte code * 2562) ...
This function is useful in -
- Code value retrieval: It allows you to retrieve the numeric code value of the leftmost character in a string.
- Character analysis: ORD() can be used for character analysis and identification purposes.
- Sorting and ordering: ORD() can be used in sorting or ordering data based on the code values of characters.
Syntax:
ORD(str)
Argument:
Name | Description |
---|---|
str | A string. |
Syntax Diagram:
MySQL Version: 8.0
Example: MySQL ORD() function
The following MySQL statement returns 119.
Code:
SELECT ORD("w3resource");
Output:
mysql> SELECT ORD("w3resource"); +-------------------+ | ORD("w3resource") | +-------------------+ | 119 | +-------------------+ 1 row in set (0.00 sec)
Video Presentation:
All String Functions (Slides presentation)
Previous: OCTET_LENGTH
Next: POSITION
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/string-functions/mysql-ord-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics