Important
The SingleStore 9.1 release candidate (RC) gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 9.1.
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.
Remarks
-
Numeric Arguments: When the argument to
HEXis numeric (e.g. integer, real, or decimal), the HEXfunction operates on the binary representation of the value as follows.-
The numeric value is treated as an unsigned
BIGINTand the result is theHEXof the unsignedBIGINTvalue. -
UNHEXis not the inverse ofHEXfor numeric values.-
For example,
UNHEX(HEX(1234)) != 1234.
-
-
-
String, BLOB, and Vector Arguments: When the argument to
HEXis a string, BLOB, or vector, each byte of the string, BLOB, or vector is converted to two hexadecimal digits.-
For example,
HEX('[1,2,3]':>VECTOR(3,F32)) = 0000803F0000004000004040.-
0000803Fis the hexadecimal representation of the floating point representation of 1 (the first element in the vector).
-
-
HEXis the inverse ofUNHEXfor strings, BLOBs, and vectors.-
For example,
UNHEX(HEX('1234')) = '1234'.
-
-
Examples
SELECT HEX(1234);
+-----------+
| HEX(1234) |
+-----------+
| 4D2 |
+-----------+SELECT HEX('1234');
+-------------+
| HEX('1234') |
+-------------+
| 31323334 |
+-------------+SELECT HEX('ohai');
+-------------+
| HEX('ohai') |
+-------------+
| 6F686169 |
+-------------+SELECT HEX('[1,2,3]':>VECTOR(3,F32));
+-------------------------------+
| HEX('[1,2,3]':>VECTOR(3,F32)) |
+-------------------------------+
| 0000803F0000004000004040 |
+-------------------------------+Related Topics
Last modified: November 21, 2025