Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

Greatest number among three given numbers in PL/SQL

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.


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: 


--To find the greatest number
-- among given three numbers
    --a assigning with 46
    a NUMBER := 46;
    --b assigning with 67
    b NUMBER := 67;
    --c assigning with 21
    c NUMBER := 21;
    --block start
    --If condition start
    IF a > b
       AND a > c THEN
      --if a is greater then print a
      dbms_output.Put_line('Greatest number is '
    ELSIF b > a
          AND b > c THEN
      --if b is greater then print b
      dbms_output.Put_line('Greatest number is '
      --if c is greater then print c
      dbms_output.Put_line('Greatest number is '
    END IF;
--end if condition
--End program 


Greatest number is 67
My Personal Notes arrow_drop_up
Last Updated : 14 Aug, 2021
Like Article
Save Article
Similar Reads