In SQLite, the ln()
function returns the natural logarithm of a number.
Syntax
ln(x)
Code language: SQL (Structured Query Language) (sql)
Arguments
x
x is the number you want to calculate the natural logarithm. x can be a literal number, an expression, or a table column.
Return type
real
The ln(x) returns the natural logarithm of x with the real type. If x is NULL
, the ln()
function returns NULL
.
If x is a string, the ln()
will attempt to convert it to a number before calculating the natural logarithm. If it cannot convert x to a number, it’ll return NULL
.
Examples
The following example uses the ln()
function to calculate the natural logarithm of 1:
SELECT ln(1);
Code language: SQL (Structured Query Language) (sql)
Output:
ln(1)
-----
0.0
Code language: SQL (Structured Query Language) (sql)
The following example uses the ln()
function to compute the natural logarithm of e:
SELECT ln(exp(1)) result;
Code language: SQL (Structured Query Language) (sql)
Output:
result
------
1.0
Code language: SQL (Structured Query Language) (sql)
In this example, exp(1)
returns e
, therefore the natural logarithm of e
is 1.
The following example uses the ln()
function to calculate the natural logarithm of NULL
:
SELECT ln(NULL) result;
Code language: SQL (Structured Query Language) (sql)
Output:
result
------
NULL
Code language: SQL (Structured Query Language) (sql)