UNHEX | Syntax: | UNHEX(String) | Return value: | CHAR | Function type: | Conversion function | |
|
|
The UNHEX() function converts a hexadecimal "String" back into a binary string.
UNHEX() cannot be used to convert a hexadecimal string back to a number.
The CONV('HEX',16,10) function is required to convert back to numbers.
If the value of the argument is NULL, UNHEX() returns NULL.
UNHEX() is the inverse function of HEX(). |
SQL Examples for the UNHEX function |
|
select conv('80',16,10);
select conv('F',16,10);
select unhex('54657374');
select unhex('313238');
SELECT unHEX(null);
|
|
conv('80',16,10) |
varchar(64) BINARY |
128 |
|
|
conv('F',16,10) |
varchar(64) BINARY |
15 |
|
|
unhex('54657374') |
varchar(4) BINARY |
Test |
|
|
unhex('313238') |
varchar(3) BINARY |
128 |
|
|
unHEX(null) |
varchar(0) BINARY |
NULL |
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the UNHEX() function in MySQL and MariaDB databases |
The UNHEX() function in MySQL and MariaDB is used to convert a hexadecimal string into its binary transform shape. The function takes a hexadecimal string as input and returns the corresponding binary data as a string, for example to convert hexadecimal encoded data, when handling binary data, performing encoding and decoding operations, or working with data in its raw binary form.
The function only works for valid hexadecimal character strings. If the input string contains non-hexadecimal characters or an odd number of characters, the function returns NULL. |
|
Further MySQL und MariaDB SQL Conversion functions |
|