The LOG function in Oracle SQL is a mathematical function that returns the logarithm of a number to a specific base.
While the LN function is always base e, the LOG function lets you choose any base you want, such as 10 (for the common logarithm) or 2.
What is the LOG Function in Oracle?
The LOG(base, number) function answers the question: "To what power must base be raised to get number?"
number(n1): Must be a positive number.base(n2): Must be a positive number other than 0 or 1.LOG(10, 100)returns2(because10^2 = 100).LOG(2, 8)returns3(because2^3 = 8).
LOG Function Syntax
The syntax for LOG requires two arguments:
LOG(n2, n1)
Let's break that down:
n2(the base): The base of the logarithm.n1(the number): The number for which you want to find the logarithm.
Oracle LOG Function Examples
Here are two practical examples of how to use LOG.
Example 1: Finding the Log Base 10 (Common Log)
This example calculates the common logarithm of 1000 (i.e., "what power of 10 gives 1000?").
Query:
SELECT
LOG(10, 1000) AS "Log_Base_10_of_1000"
FROM DUAL;
Result:
Log_Base_10_of_1000
-------------------
3
Example 2: Finding the Log Base 2
This example is common in computing and calculates the log base 2 of 64 (i.e., "what power of 2 gives 64?").
Query:
SELECT
LOG(2, 64) AS "Log_Base_2_of_64"
FROM DUAL;
Result:
Log_Base_2_of_64
----------------
6
