Explicit Cursors
Oracle Fusion / EBS · Technical · PL/SQL
GeneralHigh confidence
A named, private SQL work area you OPEN, FETCH from row by row, and CLOSE explicitly.
Grounded in: Curated Oracle knowledge layer — PL/SQL
How it works
An explicit cursor is a named, private SQL work area you declare, OPEN, FETCH from one row at a time into variables or a record, and CLOSE when done — used when you need row-by-row control that an implicit cursor (a bare SELECT INTO) or a cursor FOR loop don't give you. %NOTFOUND after a FETCH is the standard loop-exit check, since FETCH doesn't raise an exception when there's nothing left to read.
How it works
DECLARE
CURSOR c_high_earners IS
SELECT employee_id, last_name, salary FROM employees WHERE salary > 10000;
v_employee_id employees.employee_id%TYPE;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
OPEN c_high_earners;
LOOP
FETCH c_high_earners INTO v_employee_id, v_last_name, v_salary;
EXIT WHEN c_high_earners%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_last_name || ': ' || v_salary);
END LOOP;
CLOSE c_high_earners;
END;
/Related Questions
Have a follow-up, or a different question?
Continue in Ask Oracle AI