Skip to main content

UNHEX

Description​

The unhex function is used to convert a hexadecimal string back into the original string. It converts every two hexadecimal characters into one byte.

Syntax​

UNHEX(<str>)

Parameters​

ParameterDescription
<str>The hexadecimal character string

Return Value​

If the input string has a length of 0 or is odd, it returns an empty string. If the string contains characters other than [0-9], [a-f], or [A-F], it returns an empty string. In other cases, every two characters are converted to their hexadecimal representation and concatenated into a string for output.

Examples​

select unhex('@');
+------------+
| unhex('@') |
+------------+
| |
+------------+
select unhex('41');
+-------------+
| unhex('41') |
+-------------+
| A |
+-------------+
select unhex('4142');
+---------------+
| unhex('4142') |
+---------------+
| AB |
+---------------+