Cursor FOR Loops
In most cases that need an explicit cursor, you can simplify the coding by using a cursor FOR loop rather of the OPEN, FETCH, and CLOSE statements. A cursor FOR loop implicitly declares its loop index as a record that shows a row fetched from the database. Then, it opens a cursor, repeatedly fetches rows of values from the result set into fields in the record, and after that closes the cursor when all rows have been processed. In the example below, the cursor FOR loop implicitly declares emp_rec as a record:
CURSOR c1 IS
SELECT ename, sal, hiredate, deptno FROM emp;
FOR emp_rec IN c1 LOOP
salary_total := salary_total + emp_rec.sal; END LOOP;
To reference the individual fields in the record, you use dot notation, in which a dot (.) serves as the component selector.