What is LOG() in SQL?
The LOG() function returns the logarithm of a number to the specific base.
Figure 1 shows the mathematical representation of the LOG() function:
Syntax
LOG(base, number)
Parameter
This function requires two parameters:
- The
baseof the (which must be greater than one) is an optional parameter.logarithm a number - A number whose logarithm is to be calculated, it must be greater than zero.
Return Value
LOG() returns the logarithm of a number to the specific base sent as a parameter.
If the base is omitted, then the
LOG()function calculates the natural logarithm of a number, which is the same as theLOG()function with a base of the mathematical constante.
If the base is less than one, or the
numberis less thanzero, the function will returnNULL.
Example
/*example showing how to use LOG(base, number)*/-- positive number without baseselect LOG(10);-- positive number with baseselect LOG(3,3);-- zero number with baseselect LOG(2,0);-- positive number with base 0select LOG(0,2);