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
Syntax
unhex(X, Y)
Parameters
| Parameter | Description |
|---|---|
X |
Hex text. |
Y optional |
Characters to ignore between hex pairs, such as '-'. |
Return value
A BLOB, or NULL.
Examples
SELECT CAST(unhex('436F6666656520') AS TEXT) || 'Mug' AS decoded;
Output
decoded Coffee Mug
SELECT length(unhex('aa-bb-cc', '-')) AS bytes, unhex('xyz') IS NULL AS invalid;
Output
bytes | invalid 3 | 1
Version history
| Version | Change |
|---|---|
| SQLite 3.41.0 | Added |
Related
HEX()· Return the hexadecimal form of a value's bytes (its UTF-8 text for strings). Often used to display BLOBs.- SQL String Functions · tutorial