In the context of Oracle SQL, especially in PL/SQL, the different types of cursor attributes are used to provide information about the execution of DML or query statements. These attributes can be applied to both implicit and explicit cursors.
- %ROWCOUNT
Returns the number of rows affected by the last DML or SELECT INTO operation.
Usage: SQL%ROWCOUNT (for implicit), cursor_name%ROWCOUNT (for explicit)
Example:
DBMS_OUTPUT.PUT_LINE('Rows affected: ' || SQL%ROWCOUNT);
- %FOUND
Returns TRUE if the last DML or SELECT INTO affected one or more rows.
Usage: SQL%FOUND, cursor_name%FOUND
Example:
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Rows found.');
END IF;
- %NOTFOUND
Returns TRUE if the last DML or SELECT INTO affected zero rows.
Opposite of %FOUND.
Usage: SQL%NOTFOUND, cursor_name%NOTFOUND
Example:
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows found.');
END IF;
- %ISOPEN
Checks if a cursor is currently open.
Only applicable to explicit cursors — for implicit cursors (SQL%ISOPEN), it always returns FALSE since they close automatically.
Usage: cursor_name%ISOPEN
Example:
IF emp_cursor%ISOPEN THEN
DBMS_OUTPUT.PUT_LINE('Cursor is open.');
END IF;
Top comments (0)