Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle Cursor Attributes

In Oracle, While working with cursors, you may need to find the status of your cursor. The following is a list of the cursor attributes that you can use.

Oracle Cursor Attributes List

Attribute Explanation
%ISOPEN - Returns TRUE if the cursor is open, FALSE if the cursor is closed.
%FOUND - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.

- Returns NULL if cursor is open, but fetch has not been executed.

- Returns TRUE if a successful fetch has been executed.

- Returns FALSE if no row was returned.

%NOTFOUND - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.

- Return NULL if cursor is open, but fetch has not been executed.

- Returns FALSE if a successful fetch has been executed.

- Returns TRUE if no row was returned.

%ROWCOUNT - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.

- Returns the number of rows fetched.

- The ROWCOUNT attribute doesn't give the real row count until you have iterated through the entire cursor. In other words, you shouldn't rely on this attribute to tell you how many rows are in a cursor after it is opened.

Oracle Cursor Attribute Example

The following Oracle example shows how you can use the %NOTFOUND attribute:

Example

CREATE OR REPLACE Function SearchCustomer
  ( cust_name IN varchar2 )
  RETURN varchar2
IS
   adder varchar2;

   CURSOR cur1
   IS
     SELECT address
     FROM tblCustomerLoan
     WHERE firstName = cust_name;

BEGIN

   OPEN cur1;
   FETCH cur1 INTO adder;
   
   if cur1%notfound then
      adder := 'Not found';
   end if;
   
   CLOSE cur1;

RETURN adder;
END;

Note:

In the above example, shows how to use the %NOTFOUND attribute in cursor.