MariaDB: CONV Function
This MariaDB tutorial explains how to use the MariaDB CONV function with syntax and examples.
Description
The MariaDB CONV function converts a number from one number base to another and returns the result as a string value.
Syntax
The syntax for the CONV function in MariaDB is:
CONV( number, from_base, to_base )
Parameters or Arguments
- number
- The number to convert.
- from_base
- The number base that the number is currently represented in. The from_base can be a value between 2 and 36.
- to_base
- The number base to convert to. The to_base can be a value between 2 and 36, or -2 and -36.
Note
- The CONV function returns the converted number as a string value.
- If a positive to_base is specified, the CONV function treats number as an unsigned number.
- If a negative to_base is specified, the CONV function treats number as a signed number.
- The CONV function with CONV(number,10,2) syntax is equivalent to using the BIN function.
- The CONV function returns NULL if any of the parameters are NULL (ie: number, from_base, or to_base).
Applies To
The CONV function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB CONV function examples and explore how to use the CONV function in MariaDB.
For example:
SELECT CONV(3, 10, 2); Result: '11' SELECT CONV(11, 2, 10); Result: '3' SELECT CONV(79, 10, 16); Result: '4F' SELECT CONV(-79, 10, -16); Result: '-4F SELECT CONV('4F', 16, 10); Result: '79' SELECT CONV(NULL, 16, 10); Result: NULL
Advertisements