MySQL LOG2() Function
In MySQL, the LOG2()
function returns the base 2 logarithm of the specified number.
LOG2()
Syntax
Here is the syntax of MySQL LOG2()
function:
LOG2(number)
The LOG2(number)
function is the same as the LOG(2, number)
function.
Parameters
number
- Required. A number whose value must be greater than
0
.
Return value
In MySQL, the LOG2()
function returns the base 2 logarithm of the specified number.
- If
number
is less than or equal to0
, the function will returnNULL
. - If
number
isNULL
, the function will returnNULL
.
LOG2()
Examples
SELECT
LOG2(1),
LOG2(2),
LOG2(16),
LOG2(-1),
LOG2(NULL)\G
output
*************************** 1\. row ***************************
LOG2(1): 0
LOG2(2): 1
LOG2(16): 4
LOG2(-1): NULL
LOG2(NULL): NULL