Ord Function In Sql in SQL
ORD Function in SQL
The ORD() function returns the numeric code of the leftmost character of a string. It essentially gives the ASCII (or Unicode) value of that first character.
? Syntax:
ORD(string)string: The input string whose first character's code you want.
? Example:
SELECT ORD('A') AS code;Result:
| code |
|---|
| 65 |
Explanation: ASCII code of 'A' is 65.
Another example:
SELECT ORD('Hello') AS code;Returns 72 because ASCII code of 'H' is 72.
Notes:
Available in MySQL.
Only considers the first character of the string.
Useful for character code comparisons or conversions.
Want examples of similar functions like CHAR() or ASCII()?