3-6. Iterating Cursor Results Until All Rows Have Been Returned
Problem
You have created a cursor and retrieved a number of rows from the database. As a result, you want to loop through the results and do some processing on them.
Solution
Use a standard FOR
loop to iterate through the records. Within each iteration of the loop, process the current record. The following code shows the use of a FOR
loop to iterate through the records retrieved from the cursor and display each employee name and e-mail. Each iteration of the loop returns an employee with the job_id
of 'ST_MAN'
, and the loop will continue to execute until the cursor has been exhausted.
DECLARE
CURSOR emp_cur IS
SELECT *
FROM employees
WHERE job_id = 'ST_MAN'; emp_rec employees%ROWTYPE; ...
Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.