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

The HEX SQL Function in MySQL and MariaDB - Hexadecimal string

HEXSyntax:HEX(Integer or 'string')
Return value:CHAR
Function type:Conversion function
Function Description

The HEX() function returns a hexadecimal string of an integer or a string.

For a number, the HEX() function is similar to CONV(number,10,16), floating point numbers are rounded.

If the argument is a string, each byte of each character is converted into two hexadecimal digits.

If the value of the argument is NULL, HEX() returns NULL.

The inverse of HEX() is the UNHEX() function.

SQL Examples for the HEX function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

select hex(128);
select hex(15);
select CONV(128,10,16);
select CONV(15,10,16);

select hex(1.2);
select hex(1.6);

select hex('Test');
select hex('128');

SELECT HEX(null);

hex(128)
varchar(6) BINARY
80
hex(15)
varchar(4) BINARY
F
CONV(128,10,16)
varchar(64) BINARY
80
CONV(15,10,16)
varchar(64) BINARY
F
hex(1.2)
varchar(8) BINARY
1
hex(1.6)
varchar(8) BINARY
2
hex('Test')
varchar(8) BINARY
54657374
hex('128')
varchar(6) BINARY
313238
HEX(null)
varchar(0) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the HEX() function in MySQL and MariaDB databases

The HEX() function in MySQL and MariaDB is used to return a string or numeric value to its hexadecimal representation. The function takes a value as input and returns a string of the characters "0-9" and "a-f" representing the hexadecimal form of that value, for example for use with dealing with binary data, encoding and decoding operations or generating hash values.

The HEX() function converts each individual byte within a string. For strings containing multibyte characters, the hexadecimal representation of each byte is returned, not the entire character.
GET_FORMATGREATESTGROUP_CONCATHEXHOURIFIFNULL

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

OCTOCT(Integer)
More about OCT Function

UNHEXUNHEX(String)
More about UNHEX 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 HEX SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer