The syntax for the CURSOR FOR LOOP in Oracle/PLSQL is:
FOR record_index in cursor_name
Parameters or Arguments
- The index of the record.
- The name of the cursor that you wish to fetch records from.
- The statements of code to execute each pass through the CURSOR FOR LOOP.
Here is an example of a function that uses a CURSOR FOR LOOP:
CREATE OR REPLACE Function TotalIncome
( name_in IN varchar2 )
cursor c1 is
WHERE name = name_in;
total_val := 0;
FOR employee_rec in c1
total_val := total_val + employee_rec.monthly_income;
In this example, we've created a cursor called c1. The CURSOR FOR Loop will terminate after all records have been fetched from the cursor c1.