Converts a number from one base to another. CONV accepts both integer and string representations of the input number and always returns a VARCHAR result.
CONV is supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.
Syntax
VARCHAR CONV(BIGINT number, INT FROM_BASE, INT TO_BASE)
VARCHAR CONV(VARCHAR number, INT FROM_BASE, INT TO_BASE)Parameters
| Parameter | Data type | Description |
|---|---|---|
number | BIGINT or VARCHAR | The number to convert. |
FROM_BASE | INT | The base of the input number. Valid values: [2, 36]. |
TO_BASE | INT | The base to convert to. Positive valid values: [2, 36]. Negative valid values: [-36, -2]. |
Returns
A VARCHAR string representing the converted number.
For bases above 10, letters represent digits:
A= 10,B= 11, ...,Z= 35.Returns
NULLifnumberisNULLor contains characters that are invalid for the specifiedFROM_BASE.The function operates with 64-bit precision.
Examples
Base conversion
SELECT conv('100', 2, 10);
-- 4
SELECT conv('A', 16, 10);
-- 10NULL and invalid input
SELECT conv(NULL, 10, 16);
-- NULL
SELECT conv('test', 10, 2);
-- NULL (invalid characters for base 10)Table-based example
The following example uses a table T1:
| id (INT) | x (BIGINT) | y (VARCHAR) |
|---|---|---|
| 1 | 12 | '12' |
| 2 | 10 | '10' |
| 3 | 0 | 'test' |
| 4 | NULL | NULL |
Statement:
SELECT id, conv(x, 10, 16) AS var1, conv(y, 10, 2) AS var2
FROM T1;Results:
| id | var1 | var2 |
|---|---|---|
| 1 | C | 1100 |
| 2 | A | 1010 |
| 3 | 0 | NULL |
| 4 | NULL | NULL |
Row 3:
x=0converts to0in any base.y='test'is not valid base-10 input, soNULLis returned.Row 4:
NULLinput returnsNULL.