MySQL - LN() Function
The LN() function accepts a numerical value as a parameter and returns the natural logarithm of it. In other words, this function returns the base-e logarithm of the given value.
Logarithm is simply defined as the inverse of an exponent. Thus, the LN() function is also the inverse of EXP() function. The result of a logarithm is the power to which the base of the logarithm will be raised.
A logarithm can be represented as follows −
logba = p
Parameters
This function accepts the parameters as follows −
- a: any number
- b: base of the logarithm
- p: power to which the base is raised
Return Value
This function returns the natural logarithm of the given value.
Syntax
Following is the syntax of MySQL LN() function −
LN(x);
Example
The following query uses MySQL LN() function to calculate the natural logarithm (base e) of the value 9 −
SELECT LN(9) As Result;
Output
The output for the query above is produced as given below −
| Result |
|---|
| 2.1972245773362196 |
Example
If the value passed to the function is less than or equal to 0.0E0, it returns NULL.
Here, we are passing 0 as a parameter to this function −
SELECT LN(0) As Result;
Following is the output −
| Result |
|---|
| NULL |
Now, we are passing -3 to this function −
SELECT LN(-3) As Result;
Following is the output −
| Result |
|---|
| NULL |
Example
The MySQL LN() function is inverse of the EXP() function.
Here, we are passing 90 as a parameter to the EXP() function −
SELECT EXP(90) As Result;
The output will be displayed as below −
| Result |
|---|
| 1.2204032943178408e39 |
Now, we can use the output of above function as parameter to LN() function to retrieve the original value −
SELECT LN(1.2204032943178408e39) As Result;
Following is the output −
| Result |
|---|
| 90 |