Skip to main content
← PL/SQL Topics

Cursors & Bulk Operations

Explain implicit vs explicit cursors in PL/SQL

Implicit vs Explicit Cursors

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

Oracle opens an implicit cursor for every SQL statement; you declare an explicit cursor when you need to name and control one.

How it works

Any SELECT INTO, INSERT, UPDATE, DELETE or MERGE runs through an implicit cursor whose outcome you read via SQL%FOUND, SQL%NOTFOUND and SQL%ROWCOUNT immediately afterward. An explicit cursor is one you DECLARE with a name, then OPEN / FETCH / CLOSE (or drive with a cursor FOR loop) — needed for multi-row result sets, for passing a result set around as a cursor variable, or for row-by-row locking with FOR UPDATE. A cursor FOR loop over an explicit or inline cursor is the usual, safest choice.

How it works
BEGIN
  UPDATE employees SET salary = salary * 1.03 WHERE department_id = 10;
  DBMS_OUTPUT.PUT_LINE('implicit: ' || SQL%ROWCOUNT || ' rows updated');
END;
/

DECLARE
  CURSOR c_emp IS SELECT employee_id, last_name FROM employees WHERE rownum <= 5;
BEGIN
  FOR r IN c_emp LOOP        -- explicit cursor, cursor FOR loop
    DBMS_OUTPUT.PUT_LINE(r.employee_id || ' ' || r.last_name);
  END LOOP;
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI