CONV()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Converts the given numbers from the first base argument to the second base argument.
USAGE
CONV(expr, from_number_base, to_number_base)
Argument Name | Description |
---|---|
| The number to convert |
| The number base from which the number is to be converted |
| The number base to which the number is to be converted |
DETAILS
CONV()
is a mathematical function that converts the number specified as the first argument from a from_number_base
to a to_number_base
and returns the result.
Input values that contain non-decimal digits (0..10) must be specified as a string.
The "from" and "to" base arguments are integers that must be in the range of 2
to 36
(inclusive) or -36
to -2
(inclusive).
If the from_number_base
is specified as a negative number, all input values are interpreted as unsigned, even if they are large enough to set the high bit in a 64-bit value.
If the to_number_base
is specified as a negative number, positive and negative input values are differentiated by the standard prefixed minus sign (-
) in front of negative values. If the to_number_base
is specified as a positive number, then a negative input value is output as a positive value derived from its two's complement value.
A NULL
is returned if any of the arguments are NULL
or an invalid base is supplied.
EXAMPLES
SELECT CONV(10, 10, 8);
+-----------------+
| CONV(10, 10, 8) |
+-----------------+
| 12 |
+-----------------+
SELECT CONV('b', 16, 10);
+-------------------+
| CONV('b', 16, 10) |
+-------------------+
| 11 |
+-------------------+
SELECT CONV(-123, 10, 32), CONV(-123, 10, -32);
+--------------------+---------------------+
| CONV(-123, 10, 32) | CONV(-123, 10, -32) |
+--------------------+---------------------+
| FVVVVVVVVVVS5 | -3R |
+--------------------+---------------------+
SET @big = 'FVVVVVVVVVVS5';
SELECT CONV(@big, 32, -10), CONV(@big, -32, -10);
+---------------------+----------------------+
| CONV(@big, 32, -10) | CONV(@big, -32, -10) |
+---------------------+----------------------+
| -123 | NULL |
+---------------------+----------------------+