HEX
On this page
Returns the hexadecimal representation of numeric, string, or binary data.
Syntax
HEX (expression)
Arguments
-
expression: any valid expression.
This can be a column name, literal, or the return value of another function.
Return Type
Upper-case hexadecimal string.
Examples
SELECT HEX(1234);
+-----------+
| HEX(1234) |
+-----------+
| 4D2 |
+-----------+
SELECT HEX('1234');
+-------------+
| HEX('1234') |
+-------------+
| 31323334 |
+-------------+
SELECT HEX('ohai');
+-------------+
| HEX('ohai') |
+-------------+
| 6F686169 |
+-------------+
Note
This function operates on the binary representation of the given argument.hex(1234)
and hex('1234')
yield different values.hex( number )
cannot be fed into UNHEX directly to get back the literal number 1234.
Related Topics
Last modified: April 4, 2023