SQLite 3 reference · Math Functions
SQLite LN() Function
Return the natural logarithm (base e) of a number. Zero or negative numbers give NULL.
SQLite 3 Since 3.35.0
Syntax
ln(X)
Parameters
| Parameter | Description |
|---|---|
X |
A number (text that looks like a number is converted). |
Return value
A floating-point number, or NULL.
Examples
SELECT ln(1) AS a, round(ln(10), 4) AS b;
Output
a | b 0 | 2.3026
Run this on your computer — see “Get Started” for setup.
SELECT round(ln(2) / ln(1.07), 1) AS years_to_double_at_7pct;
Output
years_to_double_at_7pct 10.2
Run this on your computer — see “Get Started” for setup.
This is one of SQLite's built-in math functions, available since 3.35.0 when SQLite is compiled with
SQLITE_ENABLE_MATH_FUNCTIONS (the default for the sqlite3 command-line tool and most language bindings). The
in-browser SQLite on this site is built without them, so the examples show output from standard SQLite instead.
Version history
| Version | Change |
|---|---|
| SQLite 3.35.0 | Added |
In other languages
LN()· PostgreSQL
Related
LOG()· Return the base-10 logarithm of a number, or the logarithm in any base with log(B, X). log10() and log2() also exist.EXP()· Return e (about 2.718) raised to a power, so exp(1) is e. It is the inverse of the ln() function.- SQL Aggregate Functions · tutorial