Skip to main content

HEX

Returns the bytes of a value as an upper-case hexadecimal string. A number is converted to its text form first, so HEX(255) encodes the characters 255, not the integer.

See also:
[SELECT] [PRINTF] [ MD5 ]


Syntax​

SELECT HEX(value) FROM <multipartIdentifier>;

Arguments​

value
A string, number or BLOB.

Return Value(s)​

Returns a string. HEX(NULL) returns an empty string.


Examples​

Encode values as hexadecimal​

The following query encodes a string and a number:

SELECT HEX('stackql') AS h, HEX(255) AS n;
|----------------|--------|
| h | n |
|----------------|--------|
| 737461636B716C | 323535 |
|----------------|--------|

For more information, see https://www.sqlite.org/lang_corefunc.html#hex