Professional Documents
Culture Documents
1.Write a pl/sql program using cursor for getting user entered empno and display the name and
salary of the employee
A. Implicit cursor
declare
x emp%rowtype;
begin
end;
B.Explicit cursor
declare
V_NAME varchar2(25);
V_SAL varchar2(25);
begin
open c1;
close c1;
end;
=======================================================================
2.W.A.P. to display all record from emp table using explicit cursor lifecycle
A.
declare
i emp%rowtype;
begin
open c1;
loop
fetch c1 into i;
DBMS_OUTPUT.PUT_LINE(I.EMPNO||','||I.ENAME||','||I.MGR||','||I.SAL||','||I.JOB||','||
I.COMM||','||I.DEPTNO);
end loop;
close c1;
end;
3.W.A.P using cursor to display first 5 highest salary from emp table using % rowcount attribute.
A. declare
i emp%rowtype;
begin
open c1;
loop
fetch c1 into i;
DBMS_OUTPUT.PUT_LINE(i.empno||','||i.ename||','||i.sal);
end loop;
close c1;
end;
A.
5.W.A.P to display even number of rows from emp table using %rowcount attribute
A.
create table s1 as select * from (select ename,job, ROWNUM AS rn from emp) where mod(rn, 2) = 0;
declare
cursor c1 is select * from (select ename,job, ROWNUM AS rn from emp) where mod(rn, 2) = 0;
i s1%rowtype;
begin
open c1;
loop
fetch c1 into i;
end loop;
close c1;
end;
A.
declare
begin
for I in c1 loop
DBMS_OUTPUT.PUT_LINE(I.EMPNO||','||I.ENAME||','||I.MGR||','||I.SAL||','||I.JOB||','||
I.COMM||','||I.DEPTNO);
end loop;
end;
7.W.A.P using parameter cursor to display employee working as manager or analyst from emp table
A.
A.
declare
begin
for I in c1
loop
for j in c2(i.deptno)
loop
DBMS_OUTPUT.PUT_LINE(J.EMPNO||','||J.ENAME||','||J.MGR||','||J.SAL||','||J.JOB||','||
J.COMM||','||J.DEPTNO);
end loop;
end loop;
end;
declare
begin
for I in c1
loop
if i.job='CLERK' then
end if;
end loop;
end;
II EXERCISE ON PROCEDURES
1. W.A.P for passing empno as parameter into procedure and display NAME,SALARY from emp
A.
v_name varchar2(25);
v_salary number(5);
begin
exception
V_NAME:='NULL';
V_SALARY:=0;
A.
begin
end loop;
end;
3.W.A.P for passing emp name as a parameter and return salary of employee using out
parameter from emp
A.
is
begin
exception
V_SALARY:=0;
end;
C number(3);
begin
group by deptno;
end;
5.Enter 4 columns into emp table and use pragma autonomous transactions
pragma autonomous_transaction;
begin
commit;
end;
p;
rollback;
end;
Programs on Functions
return varchar2
is
begin
if mod(V_NUM,2)=0 then
return'Even number';
else
return'Odd number';
end if;
end;
2.W.A.P for passing empno from emp and return gross salary of the employee
A.
return number
is
gross number;
salary number;
hra number;
df number;
pf number;
begin
select sal into salary from emp where empno= V_EMPNO;
hra:=salary*0.1;
df:=salary*0.2;
Pf:=salary*0.1;
gross:=(salary+hra+df-pf);
return gross;
end;
3.W.A.P passing empno and date as parameter and return no of years that member is working
based on days
A.
,B date)
return number
is
i number;
begin
return I;
end;
4.W.A.P to pass empno and calculate tax based on conditions from employee
return number
is
vsal number;
asal number;
itax number;
begin
asal:=vsal*12;
itax:=asal*0.1;
itax:=asal*0.2;
itax:=asal*0.3;
else
itax:=0;
end if;
return itax;
end;
Programs on Triggers
begin
if :new.sal<5000 then
end if;
end;
2.W.A.T using emp, dept table and implement on delete cascading without using delete clause
begin
end;
3.W.A.T. on dept table whenever dept no into dept table automatically emp table also get
changed
begin
end;
4.W.A.T whenever user enter data into ename column should be in upper case
begin
if :new.ename=lower(:new.ename) then
end if;
end;
on departments
begin
if to_char(sysdate,'DY') in ('SAT','SUN')
then
end if;
end;
on emp
begin
if sysdate=last_day(sysdate)
then
end if;
end;
7.W.A.T. on emp table when user insert data values are stored in another table
(i) UPDATE
(ii) DELETE
A.
begin
if updating then
end;