Syntax
CONV(N, from_base, to_base)
Purpose
Converts a number from one base to another. The returned value is a string that represents the number in to_base base.
The
Ninput parameter can 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 int and string types.The
from_baseandto_baseparameters support only decimal int types, and their values must be in the range [-36, -2] ∪ [2, 36].
Invalid inputs will result in errors, including the following cases:
from_baseorto_baseis not a valid decimal int type 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 valid range for thefrom_basebase, such asfrom_basebeing 2 andNbeing 3.Nexceeds the maximum range ofBIGINT, which is [-9223372036854775807, 9223372036854775807].
Examples
obclient> SELECT CONV(9223372036854775807,10,2);
+-----------------------------------------------------------------+
| CONV(9223372036854775807,10,2) |
+-----------------------------------------------------------------+
| 111111111111111111111111111111111111111111111111111111111111111 |
+-----------------------------------------------------------------+
1 row in set
obclient> SELECT CONV('-acc',21,-7);
+--------------------+
| CONV('-acc',21,-7) |
+--------------------+
| -16425 |
+--------------------+
1 row in set
