Name

LN

Synopsis

The LN function returns the natural logarithm of a number, which is the power to which you would need to raise the mathematical constant e (approximately 2.718281) in order to get the number in question as the result.

SQL2003 Syntax

LN( expression )

DB2, Oracle, PostgreSQL

DB2, Oracle, and PostgreSQL support the SQL2003 syntax for the LN function. DB2 and PostgreSQL also support the use of LOG as a synonym for LN.

MySQL and SQL Server

MySQL and SQL Server call their natural logarithm function LOG:

LOG( expression )

Example

The following, Oracle-based example shows the natural logarithm of a number closely approximating the mathematical constant known as e:

SELECT LN(2.718281) FROM dual;
LN(2.718281)
------------
  .999999695

Use the EXP function to go in the other direction.

Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.