SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite HEX() Function



The SQLite HEX() function interprets the passed argument as a BLOB and returns a upper-case hexadecimal string rendering the content of that blob.

If the argument is an integer or floating point number, then it is interpreted as BLOB which means that the binary number is first converted into a UTF8 text representation, then that text is interpreted as a BLOB. Hence, HEX(12345678) renders as "3132333435363738" not the binary representation of the integer value "0000000000BC614E".

Syntax

HEX(X)

Parameters

X Required. Specify the value to convert to a hexadecimal representation.

Return Value

Returns the hexadecimal representation of a decimal or string value.

Example 1:

The example below shows the usage of HEX() function.

SELECT X'78797A', HEX('xyz');
Result: 'xyz', '78797A'

SELECT X'53514C', HEX('SQL');
Result: 'SQL', '53514C'

SELECT HEX(255);
Result: '323535'

SELECT HEX(500);
Result: '353030'

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 110
Data 220
Data 330
Data 440
Data 550

The statement given below can be used to get the hexadecimal representation of values of column x. Please note that it is first converted into a UTF8 text representation, then that text is interpreted as a BLOB. Then it returns the upper-case hexadecimal string rendering the content of that blob.

SELECT *, HEX(x) AS HEX_Value FROM Sample;

This will produce the result as shown below:

DataxHEX_Value
Data 1103130
Data 2203230
Data 3303330
Data 4403430
Data 5503530

❮ SQLite Functions