Quick Search:
 Oracle PL/SQL: Nested Loops: loop through tables Jump to:  
Category: >> Oracle PL/SQL >> Nested Loops: loop through tables  

<< lastnext >>

Snippet Name: Nested Loops: loop through tables

Description: This code demonstrates the use of cursors to loop through data within tables.

Also see:
» Using COMMIT in a PL/SQL loop

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 06th, 2009

   CURSOR dept_cur IS
   SELECT deptno
     FROM dept
    ORDER BY deptno;
   -- Employee cursor all employees for a dept number
   CURSOR emp_cur (v_dept_no DEPT.DEPTNO%TYPE) IS
   SELECT ename
     FROM emp
    WHERE deptno = v_dept_no;
   FOR dept_rec IN dept_cur LOOP
      DBMS_OUTPUT.put_line('Employees in Department '||TO_CHAR(dept_rec.deptno));
      FOR emp_rec IN emp_cur(dept_rec.deptno) LOOP
         DBMS_OUTPUT.put_line('...Employee is '||emp_rec.ename);
      END LOOP;

   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org