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
Ncan be an integer or a string. The minimum base is2, and the maximum base is36. Ifto_baseis a negative number,Nis treated as a signed number. Otherwise,Nis treated as an unsigned number. -
If
from_baseis a negative number, it is treated as an integer, and the sign is ignored. -
The
Nparameter supports only integer and string inputs. -
The
from_baseandto_baseparameters 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_baseorto_baseis not a valid decimal integer input; -
from_baseorto_baseis outside the range [-36, -2] ∪ [2, 36]; -
Nis not a valid numeric representation, such as a value outside the range of0to9,atoz, orAtoZ; -
Nis outside the range supported by thefrom_basebase, for example,from_baseis 2 andNis 3; -
Nexceeds the maximum range ofBIGINT, 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)