0% found this document useful (0 votes)
0 views8 pages

Pro

Uploaded by

madhavan s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

Pro

Uploaded by

madhavan s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

ODD OR EVEN

Aim:

Write a pl/sql program to check whether the given number is odd or even.

DECLARE

A number (5);

BEGIN

a:=&a;

if(a mod 2=0)then

dbms_output.put_line (a||’is even number’);

else

dbms_output.put_line(a||’is odd number’);

end if;

end;

/
POSITIVE, NEGATIVE AND ZERO

Aim:
To check whether the given number is positive, negative
and zero.

DECLARE
a number:=&a;

BEGIN

If a=0 then

dbms_output.put_line (a||’is zero’);

else

dbms_output.put_line(a||’is positive’);

end if;

else

dbms_output.put_line(a||’is negative’);

end if ;

end;
/
ZERO DIVIDE EXPECTION
Aim:
Pl/sql program to generate zero divide expection.

1.pl/sql code.
DECLAE
a number:=&a;
b number:=&b;
c number;
BEGIN
C:a/b;
dbms_output.put_line(’the result is:’||c);

EXCEPTION
When Zero divide then
dbms_output.put_line(’expection raised sorry any number is not divisible by zero’);

END;

/
FIBENACCI SERIES
Aim:
Write a pl/sql procedure to generate fibenacci series.
1.pl/sql code
Create or replace procedure fibo (n in number)
Is
a number default 0;
b number default 1;
c number;
BEGIN
dbms_output.put_line(a);

dbms_output.put_line(b);

for i..n

loop

c:=a+b;

dbms_output.put_line(c);

a:=b;

c:=c;

end loop;

end;

2.Executing procedure

DECLARE

N number;

BEGIN
n:=&n;

fibo(n);

end;

/
FUNCTION
Aim:
Write a pl/sql function to find factorial of given number.
1.pl/sql code
Create or replace function fact (n in number)
Is
f number default;
BEGIN
for i..n

loop

f:=f*i;

end loop;

Return

end;

2.Executing procedure

DECLARE

n number;

r number;

BEGIN

n:=&n;

r:=fact(n);

dbms_output.put_line(n||’!=’||r);

end;

You might also like