DB2 10.5 for Linux, UNIX, and Windows

LN scalar function

The LN function returns the natural logarithm of a number. The LN and EXP functions are inverse operations.

Read syntax diagramSkip visual syntax diagram
>>-LN--(--expression--)----------------------------------------><

The schema is SYSIBM. (The SYSFUN version of the LN function continues to be available.)

expression
An expression that returns a value of any built-in numeric data type. If the value is of decimal floating-point data type, the operation is performed in decimal floating-point; otherwise, the value is converted to double-precision floating-point for processing by the function. The value of the argument must be greater than zero (SQLSTATE 22003).

If the argument is DECFLOAT(n), the result is DECFLOAT(n); otherwise, the result is a double-precision floating-point number. The result can be null; if the argument is null, the result is the null value.

Notes

  • Results involving DECFLOAT special values: For decimal floating-point values, the special values are treated as follows:
    • LN(NaN) returns NaN.
    • LN(-NaN) returns -NaN.
    • LN(Infinity) returns Infinity.
    • LN(-Infinity) returns NaN and a warning.
    • LN(sNaN) returns NaN and a warning.
    • LN(-sNaN) returns -NaN and a warning.
    • LN(DECFLOAT('0') returns -Infinity.
  • Syntax alternatives: For compatibility with other SQL dialects, LOG can be specified in place of LN. However, because some database managers and applications use LOG to mean a common logarithm rather than a natural logarithm, use LN instead of LOG whenever possible.

Example

Assume that NATLOG is a DECIMAL(4,2) host variable with a value of 31.62.
   VALUES LN(:NATLOG)
Returns the approximate value 3.45.