Oracle PL/SQL - Cursor variables' attributes

Introduction

There are four variables:

Name Description
%FOUND checks whether a fetch succeeded in bringing a record into a variable. Returns TRUE if the fetch succeeded, FALSE otherwise.
%NOTFOUND reverse of %FOUND. Returns FALSE if the fetch succeeded, TRUE otherwise.
%ISOPENchecks whether a cursor is open.
%ROWCOUNT returns the number of rows processed by a cursor at the time the %ROWCOUNT statement is executed.

The variable properties of explicit cursors are referenced as

cursor_name%VARIABLE_NAME

To reference the c_emp cursor with the %FOUND variable, you'd do it like this:

c_emp%FOUND

For implicit cursors, the syntax is always sql%variable_name.

The last variable, %ROWCOUNT, is a regular number variable.

The first three are Boolean variables that return a logical TRUE or FALSE.

They can be used together with other logical expressions.

To ensure that the fetch succeeded and then check the value returned, you can combine them as follows:

if c_empInDept%FOUND and r_emp.eName = 'King'...

Related Topic