Declaration
CONV(N, from_base, to_base)
Description
Converts a number between different bases. The return value is a string representing the number converted from the from_base to the to_base.
The input parameter
Ncan be an integer or a string. The minimum base is2, and the maximum base is36. Ifto_baseis negative,Nis treated as a signed number. Otherwise,Nis treated as an unsigned number.If
from_baseis negative, it is treated as an integer and its sign is ignored.The
Nparameter only supports input of integer and string types.The
from_baseandto_baseparameters only support decimal integer input, with a value range of [-36, -2] U [2, 36].
Invalid input will cause an error. Invalid inputs include the following:
from_baseorto_baseis not a valid decimal integer input;The value of
from_baseorto_baseis outside the range [-36,-2] ∪ [2,36].Nis not a valid numeric representation, for example, the value exceeds the character range of0to9,atoz, andAtoZ;Nis out of the valid range forfrom_base. For example, iffrom_baseis 2,Ncannot be 3.The value of
Nexceeds the maximum representable 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