Link to home
Start Free TrialLog in
Avatar of wizard2000
wizard2000

asked on

nested cursor loops

I have a problem in that i need to create a nested loop in PL/SQL. I basically need to use information from the first loop which uses a cursor to select information in the second loop, which also uses a cursor. As it stands i can not get it working. Any help would be appreciated, especially examples.

Cheers
ASKER CERTIFIED SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grim_toaster
grim_toaster

Here's a very simple example of using an inner and outer cursor for loop:

BEGIN
FOR rec1 IN (SELECT table_name FROM user_tables) LOOP
      FOR rec2 IN (SELECT column_name FROM user_tab_columns WHERE table_name = rec1.table_name AND column_id = 1) LOOP
            DBMS_OUTPUT.put_line(rec2.column_name);      
      END LOOP;
END LOOP;
END;

If you have any particular problems, perhaps we could help you with them?