MariaDB CONV() Function
In MariaDB, it CONV()
is a built-in numeric function that converts a number from one base to another, such as from base 10 to base 2.
MariaDB CONV()
Syntax
Here is the syntax of the MariaDB CONV()
function:
CONV(num, from_base, to_base)
Parameters
num
-
Required. A number.
from_base
-
Required. The base currently used for numbers. From 2 to 36.
to_base
-
Required. The base to convert the number to. From 2 to 36.
If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONV'
.
Return value
The MariaDB CONV()
function convert numbers from one base to another.
The CONV()
function will return NULL
if any parameter is NULL
.
MariaDB CONV()
Examples
This example converts several characters in hexadecimal to decimal numbers:
SELECT
CONV('A', 16, 10),
CONV('B', 16, 10),
CONV('C', 16, 10),
CONV('D', 16, 10),
CONV('E', 16, 10),
CONV('F', 16, 10)\G
Output:
CONV('A', 16, 10): 10
CONV('B', 16, 10): 11
CONV('C', 16, 10): 12
CONV('D', 16, 10): 13
CONV('E', 16, 10): 14
CONV('F', 16, 10): 15
This example converts several numbers in base 10 to base 2:
SELECT
CONV(16, 10, 2),
CONV(32, 10, 2),
CONV(64, 10, 2)\G
Output:
CONV(16, 10, 2): 10000
CONV(32, 10, 2): 100000
CONV(64, 10, 2): 1000000
Summarize
In MariaDB, CONV()
is a built-in numeric function that converts a number from one base to another.