©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The UNHEX SQL Function in MySQL and MariaDB - Convert hexadecimal back

UNHEXSyntax:UNHEX(String)
Return value:CHAR
Function type:Conversion function
Function Description

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

 1
 2
 3
 4
 5
 6
 7
 8
 9

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: Download

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.
TRUNCATEUCASEUNCOMPRESSUNHEXUNIX_TIMESTAMPUPPERUSER

Further MySQL und MariaDB SQL Conversion functions

BINBIN(Integer)
More about BIN Function

CASTCAST(Value AS Type)
More about CAST Function

CONVCONV(Value, from Base, to Base)
More about CONV Function

CONVERTCONVERT(Expression [, in type] [, or character set])
More about CONVERT Function

HEXHEX(Integer or 'string')
More about HEX Function

OCTOCT(Integer)
More about OCT Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the UNHEX SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer