(1)
(1)
declare
i int:=1;
total int:=0;
begin
total:=total+i;
i:=i+2;
end loop;
dbms_output.put_line(‘sum: ’ ||total);
end;
declare
n1 int:=13;
factorial int:=1;
begin
factorial:=factorial*n1;
n1:=n1-1;
end loop;
dbms_output.put_line(‘Factorial ’ ||factorial);
end;
declare
a int:=0;
b int:=1;
c int;
begin
dbms_output.put_line(‘Fibonacci Series’);
dbms_output.put_line(a);
dbms_output.put_line(b);
c:=b;
b:=a+b;
dbms_output.put_line(b);
a:=c;
end loop;
end;
declare
a char(1):=’&a’;
begin
case a
end case;
end;
declare
empno int;
sal int;
begin
empno:=&empno;
if sal>10000 then
end if;
end;
2. write a sequence as 10,20,30….100 and bind it with the table product(product no,productname)
create sequence ps
start with 10
maxvalue 100
increment by 10;
//sequence created
3.write a sequence with maximum value is 40 and is incremented by 4,starts with 1 and forming a
cycle.
start with 1
maxvalue 40
increment by 4
cycle
cache 10;
sequence created.
as
begin
dbms_output.put_line(A*A);
end;
declare
A int:=12;
begin
squ(A);
end;
declare
a int:=4;
b int:=10;
c int:=8;
begin
else
end if;
end;
2)write a pl/sql block using cursor to display the employee names and their salaries till the record is
found using while loop.
declare
erec emp%rowtype;
begin
open c2;
dbms_output.put_line(erec.ename||’ ‘||erec.sal);
end loop;
close c2;
end;
as
begin
dbms_output.put_line(A*A);
end;
/
declare
A int:=12;
begin
squ(A);
end;
declare
a int:=4;
b int:=10;
c int:=8;
begin
else
end if;
end;
as
c int;
begin
c:=A;
A:=B;
B:=c;
end;
declare
A int:=12;
B int:=24;
begin
swap(A,B);
end;
return int
as
a int :=24;
begin
return a*a;
end;
return varchar
as
a int:=24;
b int:=32;
c int;
begin
a:=a;
c:=a;
a:=b;
b:=c;
end;
return number
as
z number;
begin
if(x<y) then
return x;
else
return y;
end if;
end;
4.create a trigger to update the salary of employees and to show the old salary,new salary and the
difference.
after update
on emps
for each row
begin
trigger created.
update emps
set salary=4000
where name=’DEF’;
declare
a int:=&a;
b int:=&b;
ans int;
zd exception;
begin
if b=0 then
raise zd;
end if;
ans:=a/b;
dbms_output.put_line(ans);
exception
when zd then
end;