LAB Exercise
1. Program to print first n odd numbers in descending order.
declare
n number := 10 ;
s number :=1;
i number(3);
begin
for i in reverse 1..n
loop
dbms_output.put_line(s);
s := s+2;
end loop;
end;
2. Program to print factorial series till the nth number..
Declare
num number:=5;
f number := 1;
t number;
begin
t := num;
while (num > 0)
loop
f := f * num;
num := num - 1;
end loop;
Dbms_Output.Put_line('factorial of ' || t || ' is ' || f);
end;
3. Write a PLSQL program to find out the given number is prime or not.
declare
n number :=10;
i number :=2;
f number := 1;
begin
for i in 2..n/2
loop
if mod(n,i)=0
then
f:=0;
exit;
end if;
end loop;
if f=1 then
dbms_output.put_line('prime');
else
dbms_output.put_line('not prime');
end if;
end;
4. Create a program which will update all employee’s salary. The increment will take place
based on the experience.
Experience Increament
>5000 5%
4001 to 5000 7%
3001 to 4000 10%
=<3000 12%
5. Program to print febonacci series till the nth number..
declare
a number(3):=1;
b number(3):=1;
c number(3);
n number(3):=40;
begin
while a<=n loop
dbms_output.put_line(a);
c:=a+b;
a:=b;
b:=c;
end loop;
end;