Collections:
ORD() - Order Value of First Character
How to calculate the order value of the first character in a string using the ORD() functions?
✍: FYIcenter.com
ORD(str, pos, len) is a MySQL built-in function that
order value of the first character of a giving string. For example:
SELECT ORD("dba.FYIcenter.com");
-- +--------------------------+
-- | ORD("dba.FYIcenter.com") |
-- +--------------------------+
-- | 100 |
-- +--------------------------+
SELECT ORD('O'), ORD('©'), ORD('😋');
-- +----------+-----------+-------------+
-- | ORD('O') | ORD('©') | ORD('😋') |
-- +----------+-----------+-------------+
-- | 79 | 49833 | 240 |
-- +----------+-----------+-------------+
SELECT HEX('O'), HEX('©'), HEX('😋');
-- +----------+-----------+-------------+
-- | HEX('O') | HEX('©') | HEX('😋') |
-- +----------+-----------+-------------+
-- | 4F | C2A9 | F09F988B |
-- +----------+-----------+-------------+
Reference information of the ORD() function:
ORD(str): int
If the leftmost character of the string str is a multibyte character,
returns the code for that character, calculated from the numeric
values of its constituent bytes using this formula:
(1st byte code)
+ (2nd byte code * 256)
+ (3rd byte code * 256^2) ...
If the leftmost character is not a multibyte character, ORD() returns
the same value as the ASCII() function.
Arguments, return value and availability:
str: Required. The given string to be calculated on
int: Return value. The order value of the first character.
Available since MySQL 5.7.
Related MySQL functions:
⇒ POSITION() - Synonym for LOCATE()
⇐ OCTET_LENGTH() - Synonym for LENGTH()
2023-11-13, 973🔥, 0💬
Popular Posts:
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, y...
What Is the Difference Between GETDATE() and GETUTCDATE() in SQL Server Transact-SQL? The difference...
Where to find answers to frequently asked questions on CREATE, ALTER and DROP Statements in MySQL? H...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
How AdventureWorksLT tables are related in SQL Server? There are 12 user tables defined in Adventure...