The PLSQL LOG function is used for returning the logarithm of n base m. The LOG function accepts two parameters which are used to calculate the logarithmic value. The LOG function returns a value of the numeric data type.
This function takes as an argument any numeric data type as well as any non-numeric data type that can be implicitly converted to a numeric data type. If in any case, the argument is BINARY_FLOAT or BINARY_DOUBLE, then the LOG function returns BINARY_DOUBLE, otherwise it returns number.
Syntax:
LOG( m, n )
Parameters Used:
m - It is used to specify the base number. It should be any positive numeric value except 0 and 1.
n - It is used to specify the number whose logarithmic value needs to be calculated with a specific base. It should be a positive numeric value.
Return Value:
The LOG function in PLSQL returns a numeric value.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Example-1: Using positive numeric values as arguments in the LOG function.
DECLARE
Test_Number1 number := 9;
Test_Number2 number := 3;
BEGIN
dbms_output.put_line(LOG(Test_Number1,
Test_Number2));
END;
Output:
0.5
Example-2: Using positive numeric values as arguments in the LOG function.
DECLARE
Test_Number1 number := 3;
Test_Number2 number := 9;
BEGIN
dbms_output.put_line(LOG(Test_Number1,
Test_Number2));
END;
Output:
2
Example-3: Using same positive numeric values in both the arguments in the LOG function.
DECLARE
Test_Number1 number := 3;
Test_Number2 number := 3;
BEGIN
dbms_output.put_line(LOG(Test_Number1,
Test_Number2));
END;
Output:
1
Example-4: Using zero in the base value argument in the LOG function.
DECLARE
Test_Number1 number := 0;
Test_Number2 number := 3;
BEGIN
dbms_output.put_line(LOG(Test_Number1,
Test_Number2));
END;
Output:
numeric or value error
The above example throws error because the LOG function doesn't except 0 and 1 as base values in the argument.
Example-5: Using LOG function with select query.
SELECT LOG(2, 8) "Log base 2 of 8" FROM DUAL;
Output:
3
Advantages:
The LOG function accepts any numeric datatype as well as any non-numeric datatype as an argument that can be implicitly converted to a numeric datatype.
Similar Reads
PLSQL | LN Function The LN function is an inbuilt function in PLSQL which is used to return the natural logarithm of a given input number. The natural logarithm of a number is the logarithm of that number to the base e, where e is the mathematical constant approximately equal to 2.718. This is written using the notatio
2 min read
PLSQL | LN Function The LN function is an inbuilt function in PLSQL which is used to return the natural logarithm of a given input number. The natural logarithm of a number is the logarithm of that number to the base e, where e is the mathematical constant approximately equal to 2.718. This is written using the notatio
2 min read
PLSQL | MOD Function The MOD function is an inbuilt function in PLSQL which is used to return the remainder when a is divided by b. Its formula is m - n * \left\lfloor\dfrac{m}{n}\right\rfloor. Syntax: MOD(a, b) Parameters Used: This function accepts two parameters a and b. This function gives remainder as the output wh
2 min read
PLSQL | MOD Function The MOD function is an inbuilt function in PLSQL which is used to return the remainder when a is divided by b. Its formula is m - n * \left\lfloor\dfrac{m}{n}\right\rfloor. Syntax: MOD(a, b) Parameters Used: This function accepts two parameters a and b. This function gives remainder as the output wh
2 min read
PLSQL | LEAST Function The LEAST is an inbuilt function in PLSQL which is used to return the least value from a given list of some expressions. These expressions may be numbers, alphabets etc. Syntax: LEAST(exp1, exp2, ... exp_n) Parameters Used: This function accept some parameters like exp1, exp2, ... exp_n. These each
2 min read
PLSQL | LEAST Function The LEAST is an inbuilt function in PLSQL which is used to return the least value from a given list of some expressions. These expressions may be numbers, alphabets etc. Syntax: LEAST(exp1, exp2, ... exp_n) Parameters Used: This function accept some parameters like exp1, exp2, ... exp_n. These each
2 min read