Numeric Functions
LN
Overview
LN()
will return the exponential value of its argument, which is recognized as the input parameter’s natural logarithm.
Info:
The logarithm doesn’t take negative numbers or 0.
The logarithm doesn’t take negative numbers or 0.
Syntax
The syntax of the LN()
function is described as follows.
LN (x)
x
: A positive or a negative number (or an expression that evaluates to a number).
Examples
Case #1: Basic LN() function
The example below shows that LN()
function will return the natural logarithm of the number 7,87653.
SELECT LN(7.87653);
The final result is as follows.
+-------------+
| f |
+-------------+
| 2.0638874 |
+-------------+
Case #2: Using LN() Function With a Table
In the following example, we will combine LN()
function with CREATE TABLE
statement. Therefore we can obtain natural logarithmic values of a specific column.
- Create a new table named LNTable containing the initValue column with an integer value.
CREATE TABLE LNtable(initValue int);
INSERT INTO LNtable(initValue)
VALUES (75), (18), (28);
- Run the following query to get the logarithm output of the column:
SELECT * ,LN(initValue) AS lnValue FROM LNtable;
- It will return the initial value with its natural logarithm value.
-
initValue column with the initial integer values.
-
lnValue column with the natural logarithm values.
+------------+---------------------------+
| initValue | lnValue |
+------------+---------------------------+
| 75 | 4.31748811353631 |
| 18 | 2.8903717578961645 |
| 28 | 3.332204510175204 |
+------------+---------------------------+