SQLite 3 reference · String Functions

SQLite UNHEX() Function

Decode a hexadecimal string into a BLOB, the reverse of hex(). Returns NULL if the text isn't valid hex.

SQLite 3 Since 3.41.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

unhex(X, Y)

Parameters

ParameterDescription
X Hex text.
Y optional Characters to ignore between hex pairs, such as '-'.

Return value

A BLOB, or NULL.

Examples

Decode hex to textTry it yourself
SELECT CAST(unhex('436F6666656520') AS TEXT) || 'Mug' AS decoded;

Output

decoded
Coffee Mug
Separators and bad inputTry it yourself
SELECT length(unhex('aa-bb-cc', '-')) AS bytes, unhex('xyz') IS NULL AS invalid;

Output

bytes | invalid
3 | 1

Version history

VersionChange
SQLite 3.41.0Added

Was this page helpful?