SQLite LN() Function
The SQLite LN() function returns the natural logarithm of a given number. In special cases it returns the following:
- If the number is less than or equal to 0, then NULL is returned.
Syntax
LN(number)
Parameters
number |
Required. Specify the number. Must be greater than 0. |
Return Value
Returns the natural logarithm of a given number.
Example 1:
The example below shows the usage of LN() function.
SELECT LN(1); Result: 0.0 SELECT LN(1.5); Result: 0.405465108108164 SELECT LN(2); Result: 0.693147180559945 SELECT LN(5); Result: 1.6094379124341 SELECT LN(10); Result: 2.30258509299405 SELECT LN(0); Result: NULL
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 0.5 |
Data 2 | 1 |
Data 3 | 5 |
Data 4 | 10 |
Data 5 | 50 |
The statement given below can be used to calculate the natural logarithm of column x.
SELECT *, LN(x) AS LN_Value FROM Sample;
This will produce the result as shown below:
Data | x | LN_Value |
---|---|---|
Data 1 | 0.5 | -0.693147180559945 |
Data 2 | 1 | 0.0 |
Data 3 | 5 | 1.6094379124341 |
Data 4 | 10 | 2.30258509299405 |
Data 5 | 50 | 3.91202300542815 |
❮ SQLite Functions