Thursday, March 10, 2011

Cursor Expression

SET SERVEROUTPUT ON
DECLARE
  TYPE ref_emp_cursor IS REF CURSOR;
  emp_cur ref_emp_cursor;
  l_deptno  dept.deptno%TYPE;
  l_ename    emp.ename%TYPE;
  
  CURSOR c1 IS SELECT deptno, 
         CURSOR(SELECT e.ename FROM emp e 
         WHERE e.deptno = d.deptno) 
         FROM dept d where d.dname like 'A%'; 
BEGIN
   OPEN c1;
   LOOP
    FETCH c1 INTO  l_deptno, emp_cur;
    EXIT WHEN c1%NOTFOUND;
    dbms_output.put_line('Department No '||l_deptno);
    dbms_output.put_line('========================');
    LOOP
      FETCH emp_cur INTO l_ename;
      EXIT WHEN emp_cur%NOTFOUND;
      dbms_output.put_line(emp_cur%ROWCOUNT||' Employee name is '||l_ename);
    END LOOP;
   END LOOP;
   CLOSE c1;
END;
/
Department No 10
========================
1 Employee name is CLARK
2 Employee name is KING
3 Employee name is MILLER       

No comments:

Post a Comment

External Table

Oracle External Table External tables are defined as tables that do not resides in the database allows you to access data that is stor...