Write a PL/SQL Cursor to display the different active sets at run time according to the department number. i.If department number 10 display employee name, job, salary of the 10 department. ii.If department number 20 display employee name, job, salary of the 20 department. iii.Other than this 2 departments display employee name, salary, department number of other departments.
0
Write a PL/SQL Cursor to display the different active sets at run time according to the department number.
i.If department number 10 display employee name, job, salary of the 10 department.
ii.If department number 20 display employee name, job, salary of the 20 department.
iii.Other than this 2 departments display employee name, salary, department number of other departments.
SQL>DECLARE
vempno emp.empno%type;
vempno emp.empno%type;
vsal emp.sal%type;
vjob emp.job%type;
vdeptno emp.deptno%type;
TYPE ref_c IS REF CURSOR;
c1 ref_c; --it is data type of ref_c
begin
vdeptno:=&dno;
IF vdeptno=10 THEN
OPEN c1 FOR SELECT empno,ename,sal
FROM EMP WHERE deptno=vdeptno;
ELSIF vdeptno=20 THEN
OPEN c1 FOR SELECT ename,job,sal
FROM emp WHERE deptno=vdeptno;
ELSE
OPEN c1 FOR SELECT ename,sal,deptno
FROM EMP
WHERE deptno=vdeptno;
END IF;
IF vdeptno=10 THEN
LOOP
FETCH c1 INTO vempno,vename,vsal;
EXIT WHEN C1%NOTFOUND;
Display(vempno||’ ‘||vename||’ ‘||vsal);
END LOOP;
CLOSE c1;
ELSIF vdeptno=20 THEN
LOOP
FETCH c1 INTO vename,vjob,vsal;
EXIT WHEN C1%NOTFOUND;
Display(vename||’ ‘||vjob||’ ‘||vsal);
END LOOP;
CLOSE c1;
ELSE
LOOP
FETCH c1 INTO vename,vsal,vdeptno;
EXIT WHEN c1%NOTFOUND;
display(vename||’ ‘||vsal||’ ‘||vdepto);
END LOOP;
END IF;
END;
0 comments: