Skip to main content
Version: V1.0.0

UNHEX

Syntax

UNHEX(str)

Description

The UNHEX function converts hexadecimal digits in the string str to bytes and returns a binary string.

The characters in the string str must be values in the range 0 to 9, A to F, or a to f. If the string contains any non-hexadecimal characters, the function returns NULL.

If str is a BINARY column and contains bytes filled with 0x00, the function also returns NULL. For numeric parameters N, UNHEX(N) is not the inverse of HEX(N). In such cases, you can use CONV(HEX(N),16,10) instead.

Specifically, you can use the --binary-as-hex parameter in the client connection string to indicate that binary strings should be represented in hexadecimal.

Examples

SELECT UNHEX('4f6365616e42617365');
+-----------------------------+
| UNHEX('4f6365616e42617365') |
+-----------------------------+
| OceanBase |
+-----------------------------+
1 row in set (0.001 sec)

SELECT X'4f6365616e42617365';
+-----------------------+
| X'4f6365616e42617365' |
+-----------------------+
| OceanBase |
+-----------------------+
1 row in set (0.000 sec)