Updated on 2026-11-06 GMT+08:00

hex

The hex function is used to convert an integer or character to its hexadecimal representation.

Syntax

hex(BIGINT a) 

Parameters

Parameter

Mandatory

Type

Description

a

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

The format of parameter a includes floating-point format, integer format, and string format. If parameter a is not of type BIGINT, it is implicitly converted to BIGINT type before evaluation. Strings are converted to their corresponding ASCII codes.

Return Values

Returns STRING type.

  • If a is 0, 0 is returned.
  • If a is NULL, NULL is returned.

Example Code

Returns 0.

select hex(0); 

Returns 61.

select hex('a'); 

Returns 10.

select hex(16); 

Returns 31.

select hex('1'); 

Returns 3136.

select hex('16'); 

Returns NULL.

select hex(null);