Open In App

PLSQL | LOG Function

Last Updated : 25 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. 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

Inbuilt NEXT_DAY Function in PLSQL
Prerequisite : PL/SQL IntroductionPLSQL stands for "Procedural Language extensions to SQL" and is used to transform, update and query data in a database. It is grouped into blocks that contain the declaration and statements. And it is integrated with the oracle database (since version 7). And the main idea behind PLSQL is that it adds some programm
2 min read
PLSQL | INSTR Function
The PLSQL INSTR function is used for returning the location of a substring in a string. The PLSQL INSTR function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a specified occurrence of the substring. The PLSQL INSTR function accepts four parameters whic
2 min read
PLSQL | INSTRB Function
The PLSQL INSTRB function is used for returning the location of a substring in a string, using bytes instead of characters. The PLSQL INSTRB function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a specified occurrence of the substring. The PLSQL INSTRB
2 min read
PLSQL | LENGTH2 Function
The PLSQL LENGTH2 function is used for returning the length of the specified string, in other words, it returns the length of char. UCS-2 codepoints is a character encoding standard in which characters are represented by a fixed-length 16 bits (2 bytes). UCS-2 represents a possible maximum of 65, 536 characters, or in hexadecimals from 0000h - FFFF
2 min read
PLSQL | SOUNDEX Function
The PLSQL SOUNDEX function is used for returning a phonetic representation of a string. The phonetic represents the way the string will sound. The PLSQL SOUNDEX function helps to compare words that are spelled differently, but sound alike in English. The SOUNDEX function accepts one parameter input_string which can be of any of the datatypes CHAR,
2 min read
Inbuilt Concat Function in PLSQL
Prerequisite : PLSQL BASICS Introduction : PLSQL stands for "Procedural Language extensions to SQL" and is used to transform, update and query data in a database. It is grouped into blocks that contain the declaration and statements. And it is integrated with the oracle database (since version 7). And the main idea behind PLSQL is that it adds some
3 min read
PLSQL | ASCII Function
The string in PL/SQL is actually a sequence of characters with an optional size specification. The characters could be numeric, letters, blank, special characters or a combination of all. The ASCII Function in PLSQL is used to return the NUMBER code that represents the specified character. Syntax ASCII( single_character ) Parameters Used: single_ch
1 min read
PLSQL | CONCAT Function
The string in PL/SQL is actually a sequence of characters with an optional size specification. The characters could be numeric, letters, blank, special characters or a combination of all. The CONCAT function allows you to concatenate two strings together. To CONCAT more than two values, we can nest multiple CONCAT function calls. Syntax: CONCAT( st
1 min read
PLSQL | COMPOSE Function
The string in PL/SQL is actually a sequence of characters with an optional size specification. The characters could be numeric, letters, blank, special characters or a combination of all. The Compose Function in PLSQL is used to return a Unicode string. The unistring values that can be combined with other characters in the compose function are: uni
1 min read
PLSQL | CHR Function
The string in PL/SQL is actually a sequence of characters with an optional size specification. The characters could be numeric, letters, blank, special characters or a combination of all. The CHR Function in PLSQL is the opposite of the ASCII function and is used to return the character based on the NUMBER code. Syntax: CHR( number_code ) Parameter
1 min read
Article Tags :