doc-exports/docs/dli/sqlreference/dli_spark_conv.html
Su, Xiaomeng 76a5b1ee83 dli_sqlreference_20240227
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2024-03-27 22:02:33 +00:00

8.4 KiB

conv

This function is used to convert a number from from_base to to_base.

Syntax

conv(BIGINT num, INT from_base, INT to_base)

Parameters

Table 1 Parameters

Parameter

Mandatory

Type

Description

num

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

Number whose base needs to be converted

The value can be a float, integer, or string.

from_base

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

It represents the base from which the number is converted.

The value can be a float, integer, or string.

to_base

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

It represents the base to which the number is converted.

The value can be a float, integer, or string.

Return Values

The return value is of the STRING type.

  • If the value of num, from_base, or to_base is NULL, NULL is returned.
  • The conversion process works with 64-bit precision and returns NULL when there is overflow.
  • If the value of num is a decimal, it will be converted to an integer before the base conversion, and the decimal part will be discarded.

Example Code

The value 8 is returned.

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

The value B is returned.

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

The value 703710 is returned.

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

The value 27 is returned.

select conv(1000.123456, 3.123456, 10.123456);

The value 18446744073709551589 is returned.

select conv(-1000.123456, 3.123456, 10.123456);

The value NULL is returned.

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