SQLite ln() Function

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

In SQLite, the ln() function returns the natural logarithm of a number.

Syntax #

ln(x)

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);

Output:

ln(1)
-----
0.0

The following example uses the ln() function to compute the natural logarithm of e:

SELECT ln(exp(1)) result;

Output:

result
------
1.0

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;

Output:

result
------
NULL

Was this tutorial helpful?