In this guide, we will explain how to use the MySQL CONV function with syntax and examples.
Description
The MySQL 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 MySQL 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 between 2 and 36.
to_base
The number base to convert to. The to_base can be 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 :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some CONV function examples and explore how to use the CONV function.
For example:
mysql> SELECT CONV(5, 10, 2); Result: '101' mysql> SELECT CONV(101, 2, 10); Result: '5' mysql> SELECT CONV(74, 10, 16); Result: '4A' mysql> SELECT CONV(-74, 10, -16); Result: '-44 mysql> SELECT CONV('4A', 16, 10); Result: '74'
Next Topic : Click Here
Pingback: MySQL: CONNECTION_ID Function | Adglob Infosystem Pvt Ltd