Oracle LN Function: A Simple Guide

The LN function in Oracle SQL is a mathematical function that returns the natural logarithm of a number. The natural logarithm is the logarithm to the base e, where e is a mathematical constant approximately equal to 2.71828183.

This function is the inverse of EXP (which raises e to a power). It's commonly used in scientific, statistical, and financial calculations.

What is the LN Function in Oracle?

The LN function answers the question: "To what power must e be raised to get the number n?"

  • n must be greater than 0. You cannot take the natural logarithm of zero or a negative number.
  • LN(1) returns 0 (because e^0 = 1).
  • LN(e) (or LN(EXP(1))) returns 1 (because e^1 = e).

LN Function Syntax

The syntax for LN is very simple:

LN(n)

Let's break that down:

  • n: The number for which you want to find the natural logarithm. It must be a positive number.

Oracle LN Function Examples

Here are two practical examples of how to use LN.

Example 1: Finding the Natural Log of 1

This example shows a fundamental property of logarithms: the log of 1 is always 0.

Query:

SELECT 
  LN(1) AS "Log_of_1"
FROM DUAL;

Result:

  Log_of_1
----------
         0

Example 2: Finding the Natural Log of a Number

This example calculates the natural logarithm of 95.

Query:

SELECT 
  LN(95) AS "Natural_Log_of_95"
FROM DUAL;

Result:

Natural_Log_of_95
-----------------
       4.55387689
Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted