Experiment-18
Object: Write a PL/SQL code to find the
greatest number among the given set of numbers.
Requirement: Windows XP, Oracle 9i.
Program Code:
SQL> declare
2 a number:=&enter_a;
3 b number:=&enter_b;
4 c number:=&enter_c;
5 begin
6 if a>b then
7 if a>c then
8 dbms_output.put_line('A is greatest');
9 else
10 dbms_output.put_line('B is greatest');
11 end if;
12 else
13 if b>c then
14 dbms_output.put_line('C is greatest');
15 end if;
16 end if;
17 end;
18 .
So in above program code i have declared three variables in line 2,3 and 4 after that i have checked if a is greater than b,if this is true then check if a is also greater than c and if yes then a is greatest otherwise b is greatest.So this program has very simple logic.
OUTPUT:
SQL> /
Enter value for enter_a: 3
old 2: a number:=&enter_a;
new 2: a number:=3;
Enter value for enter_b: 5
old 3: b number:=&enter_b;
new 3: b number:=5;
Enter value for enter_c: 1
old 4: c number:=&enter_c;
new 4: c number:=1;
C is greatest
PL/SQL procedure successfully completed
RESULT : The
above program to find the greatest number among the given set of numbers has
been successfully executed.