PLSQL | LEAST Function

The LEASE 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 expression may be numbers or alphabets on which LEAST() function is called.



Return Value:
This function returns the least value from a given list of expressions.

Supported Versions of Oracle/PLSQL is given below:

  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i

Let’s see some examples which illustrate the LEAST function:

Example-1:

DECLARE 
   Test_Number number1 := 1;
   Test_Number number2 := 2;
   Test_Number number3 := 5;
   Test_Number number4 := 30;
   
BEGIN 
   dbms_output.put_line(LEAST(Test_Number number1, 
                              Test_Number number2, 
                              Test_Number number3, 
                              Test_Number number4)); 
   
END; 

Output:

1

In the above example, some list of numbers is taken as the parameter out of which least i.e, the smallest number is returned as the output. for example, in the first example 1, 2, 5 and 30 is taken as the parameter out of which 1 is returned because it is the smallest number.

Example-2:

DECLARE 
   Test_Number number1 := 'a';
   Test_Number number2 := 'b';
   Test_Number number3 := 'c';
   
BEGIN 
   dbms_output.put_line(LEAST(Test_Number number1, 
                              Test_Number number2, 
                              Test_Number number3)); 
   
END;  

Output:

a

In the above example, some list of alphabets is taken as the parameter out of which least i.e, smallest in count alphabet is returned as the output. for example, in example2 a, b and c is taken as the parameter out of which a is returned because it is the smallest in the count.

Example-3:

DECLARE 
   Test_Number number1 := 0;
   Test_Number number2 := -4;
   Test_Number number3 := 0.6;
   
BEGIN 
   dbms_output.put_line(LEAST(Test_Number number1, 
                              Test_Number number2, 
                              Test_Number number3)); 
   
END; 

Output:

-4

In the above example, some list of numbers is taken as the parameter out of which least i.e, the smallest number is returned as the output. for example, in the example3 0, -4 and 0.6 is taken as the parameter out of which -4 is returned because it is the smallest number.

Advantage:
This function is used to find out the smallest number out of given some input numbers.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.