Cloud

ln

The ln() function returns the natural logarithm of its argument.

ln() does not accept negative numbers or zero.

Syntax

The syntax of the ln() function is:

LN (x)

x: A positive number, or an expression that evaluates to a positive number.

Examples

Basic ln() function

The following example returns the natural logarithm of 7.87653:

SELECT LN(7.87653);

The query returns:

+-------------+
| f           |
+-------------+
| 2.0638874   |
+-------------+

Use ln() function with a table

This example combines the ln() function with a CREATE TABLE statement to obtain natural logarithmic values of a specific column:

  1. Create a new table named LNtable with an integer initValue column.

    CREATE TABLE LNtable(initValue int);
    INSERT INTO LNtable(initValue)
    VALUES (75), (18), (28);
  2. Run this query to get the logarithm output of the column:

    SELECT * ,LN(initValue) AS lnValue FROM LNtable;
  3. The query returns the initial value and its natural logarithm:

    • initValue: The original integer values.

    • lnValue: The natural logarithm values.

      +------------+---------------------------+
      | initValue  | lnValue                   |
      +------------+---------------------------+
      | 75         | 4.31748811353631          |
      | 18         | 2.8903717578961645        |
      | 28         | 3.332204510175204         |
      +------------+---------------------------+