Categories: MySQL FunctionsPHP

MySQL8 ORD() Functions – String Functions

This function helps in getting the numeric value of the leftmost character of a input string.

[table caption=”” width=”100%” colwidth=”50%|50%” colalign=”left|left”]

If the leftmost character, returned value
is a multibyte character, the returned value is calculated from the numeric values of its constituent bytes.

is not a multibyte character, the return value is its ASCII code (i.e it gives similar value which ASCII() function returns) .
[/table]

Note : If the leftmost character is not a multibyte character, ORD() returns the same value as the ASCII() function.

ORD() : Syntax

ORD( string );


ORD() : Parameter

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description
string , Required, String , This is input string from which we want the numeric code of the first character from starting.
[/table]


ORD() : Output

[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Returns,
Number, returns the numeric value of the leftmost character of the input string.
[/table]


ORD() : Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 5.7
[/table]


ORD() Example 1 : Simple example with literal strings.

mysql> SELECT ORD('Tuts');
+-------------+
| ORD('Tuts') |
+-------------+
|          84 |
+-------------+
1 row in set (0.00 sec)

ORD() Example 2 : Simple example with literal strings.

Ascii value for the e.g.1 is same for both input. Both function returns same values.

mysql> SELECT ORD('T'), ASCII('T');
+----------+------------+
| ORD('T') | ASCII('T') |
+----------+------------+
|       84 |         84 |
+----------+------------+
1 row in set (0.00 sec)

ORD() Example 3 : Multibyte Characters

Below example will have multibyte character. So, returned values are calculated from the numeric values of its constituent bytes.

mysql> SELECT ORD('€'), ORD('§');
+------------+-----------+
| ORD('€')   | ORD('§')  |
+------------+-----------+
|   14844588 |     49831 |
+------------+-----------+
1 row in set (0.00 sec)

ORD() Example 4 : NULL Arguments

It will return NULL, if the argument is NULL. Lets see the below example.

mysql> SELECT ORD(NULL);
+-----------+
| ORD(NULL) |
+-----------+
|      NULL |
+-----------+
1 row in set (0.00 sec)

ORD() Example 5 : Uppercase and Lowercase value are different

Uppercase and Lowercase characters have a different numeric value. Hence, it is Case Sensitive function for alphabets. Below example will show this:

mysql> SELECT ORD('A'), ORD('a'), ASCII('A'), ASCII('a');
+----------+----------+------------+------------+
| ORD('A') | ORD('a') | ASCII('A') | ASCII('a') |
+----------+----------+------------+------------+
|       65 |       97 |         65 |         97 |
+----------+----------+------------+------------+
1 row in set (0.00 sec)

See all MySQL String functions MySQL 8 String Functions.


Related articles : ASCII(), OCT(), LENGTH(), OCTET_LENGTH(), BIT_LENGTH(), CHAR() , CHARACTER_LENGTH(), CHAR_LENGTH().


PHP Related articles : CHR(), ORD() , STRLEN(), SUBSTR_COUNT(), COUNT_CHARS(), STRSTR() ,STRCSPN(), PHP STRING FUNCTIONS().


jyoti rani

Recent Posts

Exploring the Best Toy Store in Noida: A Paradise for Kids and Collectors

Toys have always played a crucial role in childhood, fueling imagination, creativity, and learning. Whether you're looking for educational playsets,…

1 day ago

A Unique Toy Shopping Experience: The Best Toy Store in Delhi and Across India

Toys are an essential part of childhood, shaping creativity, learning, and fun-filled memories. Whether it’s the soft embrace of plush…

2 days ago

A World of Play: The Best Toy Shopping Experience in Noida

Toys are a gateway to imagination, creativity, and learning. Whether it’s a child’s first plush toy, a set of engaging…

3 days ago

The Ultimate Guide to Finding the Best Toy Shops in Gurgaon

Toys are more than just playthings; they help children explore, learn, and develop essential life skills. From interactive sensory toys…

4 days ago

The Ultimate Toy Shopping Guide: Finding the Best Toy Store in Noida

Toys are more than just playthings; they are tools that foster creativity, motor skills, and cognitive development in children. From…

5 days ago

Exploring the Best Toy Shop in Delhi: A Blend of Fun, Learning, and Creativity

Toys play an integral role in a child’s growth and development. They spark creativity, encourage learning, and provide endless hours…

1 week ago