MySQL LN() Function

The LN() function in MySQL calculates the natural logarithm of a number. The natural logarithm uses the mathematical constant *e* (Euler's number, approximately 2.71828) as its base.



LN(): Definition and Usage

Natural logarithms are fundamental in mathematics and various scientific fields. The LN() function provides a way to compute these logarithms directly within your MySQL queries. The input number must be positive; otherwise, you'll get an error.

Syntax

Syntax

LN(number)
      

Parameter Values

Parameter Description
number The number for which you want to calculate the natural logarithm. This is required and must be a positive number.

Related Functions

For logarithms with other bases, see the LOG() function. The EXP() function calculates the exponential (inverse of the natural logarithm).

Examples

Natural Logarithm of 2

This example calculates the natural logarithm of 2.

Syntax

SELECT LN(2);
      
Output

0.693147180559945
      

Natural Logarithm of 1

The natural logarithm of 1 is 0.

Syntax

SELECT LN(1);
      
Output

0
      

**Note:** The output values are approximate due to floating-point limitations. The exact value might vary slightly depending on your MySQL version. If you use a non-positive number as input, you'll get an error.