MySQL UNHEX Function

MySQL UNHEX is one of the String functions, which is to convert the Hexadecimal number into the bytes represented by the Number. The return value of this method is a binary string. We can call this UNHEX function an inverse of HEX(), and the basic syntax of it is as shown below:

SELECT UNHEX(String_Value);

The characters that we specify as the UNHEX function argument must represent legal hexadecimal digits, such as 0 to 9, A to F, and a to f. If you provide any of the non-hexadecimal digits, it returns NULL.

MySQL UNHEX Function Example

The UnHexadecimal Function in MySQL converts the Hexadecimal digits to a string. The following String Function query shows you multiple ways to use this UNHEX function. Also, read about the MySQL HEX function.

SELECT UNHEX('4D7953514C');

SELECT UNHEX('5475746F7269616C2047617465776179');

SELECT UNHEX('48656C6C6F');
UNHEX Example 1

Let me take another MySQL example.

TIP: Please refer to the MySQL ASCII and MySQL CHAR methods from the list of available MySQL string functions.

SELECT UNHEX('31303030');

SELECT UNHEX('31303040');

SELECT UNHEX('31302040');
UNHEX Function 2