Syntax
CONV(N, from_base, to_base)
Purpose
CONV() converts numbers from one number base into another. The return value is a string converted from from_base to to_base.
The parameter
Ncan be an integer or string. The minimum base is2and the maximum base is36.Nis considered a signed number ifto_baseis a negative number. Otherwise,Nis considered an unsigned number.If
from_baseis a negative number, N is considered an integer, and the sign is ignored.The parameter
Nsupports only the int and string types.The
from_baseandto_baseparameters support only the decimal int type, and the value range is [-36,-2] U [2,36].
Invalid inputs can cause errors. The following are scenarios of invalid inputs:
The
from_baseorto_baseparameter is not of the valid decimal int type.The
from_baseorto_baseparameter exceeds the value range of [-36,-2] U [2,36].Nis not a valid numeric value. For example, the value is beyond the ranges of 0 to 9, a to z, and A to Z.Nis beyond the value range offrom_base. For examplefrom_baseis 2, butNis 3.Nexceeds the maximum value range [-9223372036854775807,9223372036854775807] of theBIGINTtype.
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