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 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:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- 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.
Similar Reads
PLSQL | GREATEST Function The GREATEST function in PL/SQL is a tool for comparing multiple values and returning the largest one from a given list of expressions. Whether we are working with numbers, strings, or dates, the function determines the greatest value based on their data type.In this article, We will learn about the
4 min read
PLSQL | LAST_DAY Function The PLSQL LAST_DAY function is used for returning the last day of the month based on a date value. The last day of the month is defined by the session parameter NLS_CALENDAR. The LAST_DAY function accepts one parameter which is the date value used to calculate the last day of the month. The LAST_DAY
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 | LOWER Function The PLSQL LOWER function is used for converting all letters in the specified string to lowercase. If there are characters in the string that are not letters, they are unaffected by this function. The char to be converted can be any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or
1 min read
LEAST() Function in MySQL The LEAST() function in MySQL is a versatile tool that returns the smallest (minimum) value from a list of expressions. It can be used with numbers, strings, or even columns of data to find the minimum value according to their data type.In this article, We will learn about LEAST() Function in MySQL
4 min read
PLSQL | LOG Function 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-nu
2 min read
SQL LAG() Function The LAG() function in SQL is one of the most powerful and flexible tools available for performing advanced data analysis. It is often used to compare rows, calculate differences, and tracks trends in a dataset, especially for time-series data. If we are working with sales, stock prices, or even empl
5 min read
PL/SQL Functions PL/SQL functions are reusable blocks of code that can be used to perform specific tasks. They are similar to procedures but must always return a value. A function in PL/SQL contains:Function Header: The function header includes the function name and an optional parameter list. It is the first part o
4 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
MySQL | LAST_DAY() Function The MySQL LAST_DAY() function returns the last day of the month for a given date or datetime. This function takes a date value as an argument and returns the last day of the month for that date. The date argument should be a valid date or datetime.SyntaxLAST_DAY( Date );Parameters:Date: The LAST_DAY
3 min read