This topic describes how to use the built-in function CONV that converts numeral systems in Realtime Compute.

Note Blink 3.2.2 and later support this function.

Syntax

VARCHAR CONV(BIGINT number, INT FROM_BASE, INT TO_BASE)
or 
VARCHAR CONV(VARCHAR number, INT FROM_BASE, INT TO_BASE)

Input parameters

Parameter Data type
number BIGINT or VARCHAR.
FROM_BASE INT type. This parameter cannot be negative. Valid values: [2, 36].
TO_BASE INT type. This parameter can be positive (unsigned integer), negative (signed integer), or ABS(TO_BASE). Valid values: [2, 36].

Description

Converts a number of the BIGINT or VARCHAR type from one numeral system to another. The return value is of the STRING type. The CONV() precision is 64 bits.
Note If the value of the number parameter is null or an invalid character, NULL is returned.

Example

  • Test data
    id (INT) x (BIGINT) y (VARCHAR)
    1 12L '12'
    2 10L '10'
    3 0L 'test'
    4 NULL NULL
  • Test statements
    SELECT  id, conv(x, 10, 16) as var1, conv(y, 10, 2) as var2
    FROM T1;
  • Test results
    id (INT) var1 (VARCHAR) var2 (VARCHAR)
    1 C 1100
    2 A 1010
    3 O NULL
    4 NULL NULL