Monday, January 25, 2016

Database Cursors?

In this post I am going to discuss about Database cursor on a high level.

Database Cursors:
Cursors is a PL/SQL construct that allows us to name these work areas, to access and traverse the information stored in the database object.

Database Cursor types: 
There are two cursor types, namely
-Implicit Cursor
-Explicit Cursor

Implicit Database Cursor: 
Declared by PL/SQL or Database engine implicitly for all DML (Insert, Delete, & Update Queries) statements and single row queries. These Database operation are performed in the background when we execute DMLs against a given database session.

Explicit Database Cursor:
Declared explicitly by the User, along with other identifiers to be used in a Block.
for queries only, and allow multiple rows to be processed from the query.

Database Cursor Syntax:
SQL>CURSOR<cursor name> IS <select statement>;

Database Cursor attributes: Each cursor has four main attributes
%NOTFOUND: Evaluates to false when last fetch Succeeded.
%FOUND: Evaluates to true when last fetch Succeeded.
%ROWCOUNT: Returns the number of rows fetched
%ISOPEN: Evaluates to true cursor object is initialized and ready to perform.

Implicit Database Cursor attributes:
SQL%NOT FOUND
SQL%FOUND
SQL%ROWCOUNT

Database Cursor actions:
OPEN - To initialized cursor object and get ready to perform actions
FETCH - To fetch record/s set to perform further operations
CLOSE - To close or release memory once all the intended operations are performed

***Please note that the above actions can not be used to manipulate the Implicit Cursor.




0 comments:

Post a Comment