Greatest number among three given numbers in PL/SQL
Prerequisite – PL/SQL introduction
In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations.
Given three numbers and the task is to find greatest among them.
Examples:
Input: a = 46, b = 67, c = 21
Output: 67
Input: a = 9887, b = 4554, c = 212
Output: 9887
Approach is to consider the first number and compare it with other two numbers. Similarly, check with second and third.
Below is the required implementation:
SQL
DECLARE
a NUMBER := 46;
b NUMBER := 67;
c NUMBER := 21;
BEGIN
IF a > b
AND a > c THEN
dbms_output.Put_line( 'Greatest number is '
||a);
ELSIF b > a
AND b > c THEN
dbms_output.Put_line( 'Greatest number is '
||b);
ELSE
dbms_output.Put_line( 'Greatest number is '
||c);
END IF;
END ;
|
Output:
Greatest number is 67
Last Updated :
14 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...