Cursor FOR Loop Record Variable
ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated
A cursor FOR loop implicitly declares a record of type cursor%ROWTYPE, scoped to the loop.
How it works
FOR r IN c LOOP silently declares r as c%ROWTYPE, opens the cursor, fetches each row into r, and closes it — even if an exception exits the loop. r exists only inside the loop; you cannot see the last row after END LOOP. To reference the shape elsewhere, declare your own variable AS c%ROWTYPE. Column aliases in the cursor's SELECT become the record's field names, so alias every expression.
How it works
DECLARE
CURSOR c_pay IS
SELECT e.last_name,
e.salary * 12 AS annual_salary -- alias -> field name
FROM employees e
WHERE e.department_id = 30;
r_row c_pay%ROWTYPE; -- reuse the shape
BEGIN
FOR r IN c_pay LOOP
r_row := r;
DBMS_OUTPUT.PUT_LINE(r.last_name || ': ' || r.annual_salary);
END LOOP;
DBMS_OUTPUT.PUT_LINE('last seen: ' || r_row.last_name);
END;
/Related questions
GroundingGenerated
Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.