Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
HEX
On this page
The HEX() function 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: