Search This Blog

Tuesday 17 January 2012

PL/SQL Programs for Interview


PL / SQL PROGRAMS

P1. WRITE A NESTED PROGRAM TO ADD AND TO MULTIPLY TWO NUMBERS.
DECLARE
N1 number;
N2 number;
Sum number ;
BEGIN
Sum := N1+N2 ;
<< inner_block >>
DECLARE
Prod number;
BEGIN
Prod := N1 * N2 ;
Dbms_output.put_line( "Product Value ="|| prod );
END inner_block ;
Dbms_output.put_line( "Sum Value ="||sum);
END;

P2. WRITE A PROGRAM TO CALCULATE THE SIMPLE INTEREST AND COMPUND INTEREST ,
IF P, N, R ARE GIVEN.
declare
p number(9,2) ;
n number(9,2) ;
r number(9,2) ;
si number(9,2) := 0;
ci number(9,2) := 0;
begin
p := &principal_amount;
n := &no_of_years;
r := &rate_of_interest;
si := p*n*r/100;
ci := p*(1+r/100)**n;
dbms_output.put_line("simple interset ="||si);
dbms_output.put_line("compound interset ="||ci);
end;

SQL> /
Enter value for principal_amount: 10000
old 8: p:=&principal_amount;
new 8: p:=10000;
Enter value for no_of_years: 5
old 9: n:=&no_of_years;
new 9: n:=5;
Enter value for rate_of_interest: 10.5
old 10: r:=&rate_of_interest;
new 10: r:=10.5;
simple interset =5250
compound interset =16474.47
PL/SQL procedure successfully completed.
PROGRAM BASED ON IF LOOP

P3 . Write a program to check greatest of two numbers :
declare
a number(3) :=20;
b number(3) :=10;
begin
if a>b then
dbms_output.put_line("a is the greatest :"||a);
else
dbms_output.put_line("B is the greatest :"||b);
end if;
end;

SQL> /
a is the greatest : 20
PL/SQL procedure successfully completed.

P4. Given 2 sides of a rectangle .Write a program to find out its area is gr
eater than its perimeter or not .
declare
l number;
b number;
ar number;
pr number;
begin
l := &l;
b := &b;
ar := l*b;
pr := 2*(l+b);
if ar > pr then
dbms_output.put_line("the area iS > its perimeter"|| "area = "||ar||"perimeter ="||pr);
else
dbms_output.put_line("the area iS < its perimeter"||"area ="||ar||"perimeter ="||pr);
end if;
end;

Enter value for l: 10
old 7: l:=&l;
new 7: l:=10;
Enter value for b: 6
old 8: b:=&b;
new 8: b:=6;
the area is > its perimeter area = 60 perimeter = 32
PL/SQL procedure successfully completed.

P5. WRITE A PROGRAM TO INPUT A SINGLE DIGIT NO: CONVERT IT INTO WORDS.
Declare
a number;
t varchar2(10);
begin
a :=&a;
if a=1 then
t := 'one';
elsif a=2 then
t := 'two';
elsif a= 3 then
t := 'three';
elsif a= then
t := 'four';
elsif a=5 then
t := 'five';
elsif a=6 then
t := 'six';
elsif a=7 then
t := 'seven';
elsif a=8 then
t := 'eight';
elsif a=9 then
t := 'nine';
else
t := 'zero';
end if;
dbms_output.put_line(a||"="||t);
end;

Enter value for a: 2
old 5: a:=&a;
new 5: a:=2;
2 = two
PL/SQL procedure successfully completed



1 comment:

  1. Hi, Nice PL/SQL Programs for Interview.Thanks, its really helped me a lot..

    -Aparna
    Theosoft

    ReplyDelete