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

conv

The conv function is used to convert a number num from base from_base to base to_base.

Syntax

conv(BIGINT num, INT from_base, INT to_base) 

Parameters

Parameter

Mandatory

Type

Description

num

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

The number to be converted. The format of parameter num includes floating-point format, integer format, and string format.

from_base

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

The source base from_base. The format of parameter from_base includes floating-point format, integer format, and string format.

to_base

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

The target base to_base. The format of parameter to_base includes floating-point format, integer format, and string format.

Return Values

Returns STRING type.

  • If num, from_base, or to_base is NULL, NULL is returned.
  • The conversion process works with 64-bit precision. NULL is returned on overflow.
  • If num is a decimal number, it is converted to an integer value before the base conversion. The fractional part is discarded.

Example Code

Returns 8.

select conv('1000', 2, 10); 

Returns B.

select conv('1011', 2, 16); 

Returns 703710.

select conv('ABCDE', 16, 10); 

Returns 27.

select conv(1000.123456, 3.123456, 10.123456); 

Returns 18446744073709551589.

select conv(-1000.123456, 3.123456, 10.123456); 

Returns NULL.

select conv('1100', null, 10);