Skip to main content
Version: V1.0.0

CONV

Declaration

CONV(N, from_base, to_base)

Description

Converts a number from one base to another. The return value is a string that represents the number in the to_base base.

  • The input parameter N can be an integer or a string. The minimum base is 2, and the maximum base is 36. If to_base is a negative number, N is treated as a signed number. Otherwise, N is treated as an unsigned number.

  • If from_base is a negative number, it is treated as an integer, and the sign is ignored.

  • The N parameter supports only integer and string inputs.

  • The from_base and to_base parameters support only decimal integer inputs, and their values must be in the range [-36, -2] ∪ [2, 36].

Invalid inputs will result in an error, including the following cases:

  • from_base or to_base is not a valid decimal integer input;

  • from_base or to_base is outside the range [-36, -2] ∪ [2, 36];

  • N is not a valid numeric representation, such as a value outside the range of 0 to 9, a to z, or A to Z;

  • N is outside the range supported by the from_base base, for example, from_base is 2 and N is 3;

  • N exceeds the maximum range of BIGINT, which is [-9223372036854775807, 9223372036854775807].

Examples

SELECT CONV(9223372036854775807,10,2);
+-----------------------------------------------------------------+
| CONV(9223372036854775807,10,2) |
+-----------------------------------------------------------------+
| 111111111111111111111111111111111111111111111111111111111111111 |
+-----------------------------------------------------------------+
1 row in set (0.001 sec)

SELECT CONV('-acc',21,-7);
+--------------------+
| CONV('-acc',21,-7) |
+--------------------+
| -16425 |
+--------------------+
1 row in set (0.001 sec)