MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL LN() Function



The MySQL LN() function returns the natural logarithm of a given number. In special cases it returns the following:

  • If the number is less than or equal to 0, then NULL is returned.

Syntax

LN(number)

Parameters

number Required. Specify the number. Must be greater than 0.

Return Value

Returns the natural logarithm of a given number.

Example 1:

The example below shows the usage of LN() function.

mysql> SELECT LN(1);
Result: 0

mysql> SELECT LN(1.5);
Result: 0.4054651081081644

mysql> SELECT LN(2);
Result: 0.6931471805599453

mysql> SELECT LN(5);
Result: 1.6094379124341003

mysql> SELECT LN(10);
Result: 2.302585092994046

mysql> SELECT LN(0);
Result: NULL

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 10.5
Data 21
Data 35
Data 410
Data 550

The statement given below can be used to calculate the natural logarithm of column x.

SELECT *, LN(x) AS LN_Value FROM Sample;

This will produce the result as shown below:

DataxLN_Value
Data 10.5-0.6931471805599453
Data 210
Data 351.6094379124341003
Data 4102.302585092994046
Data 5503.912023005428146

❮ MySQL Functions