MySQL HEX is one of the String Functions, which is to convert the given value to the Hexadecimal number. The HEX function returns the string representation of that Hexadecimal number, and the basic syntax of this one is
SELECT HEX(N)
SELECT HEX(String_Value);
MySQL Hexadecimal Function Example
This method converts the user specified number or String to Hexadecimal Number. Next, it returns the Output in a String format. The following query shows you multiple ways to use this MySQL HEX function on small and large Numeric values. Also, read about the MySQL UNHEX function.
SELECT HEX(10);
SELECT HEX(2500);
SELECT HEX(1900), HEX(34567890);
+------+------+------+---------+
| A | B | C | D |
+------+------+------+---------+
| A | 9C4 | 76C | 20F76D2 |
+------+------+------+---------+
Let me take another example to show the HEX String method. If we specify the text or words as the argument, then this MySQL method converts each byte of a character in a string into a hexadecimal digit.
TIP: Please refer to the MySQL ORD and MySQL CHAR methods from the list of available MySQL string functions.
SELECT HEX('Hi');
SELECT HEX('Tutorial Gateway');
SELECT HEX('MySQL');
