PLSQL Cursor
PLSQL Cursor
Types of cursor :-
1. Implicit cursor
2. Explicit cursor
1.) Implicit cursor :- If the Oracle engine opened a cursor for its internal processing
it is known as an Implicit Cursor. The implicit cursors are automatically generated
by Oracle while an SQL statement is executed. These are created by default to
process the statements when DML statements like INSERT, UPDATE, DELETE etc. are
executed.
Syntax :-
DECLARE
CURSOR <cursor_name> IS <SELECT statement^>
<cursor_variable declaration>
BEGIN
OPEN <cursor_name>;
FETCH <cursor_name> INTO <cursor_variable>;
……..
/* process the records;*/
………
. CLOSE <cursor_name>;
END;
1.) DECLARE :- Declare the cursor in the Declaration section.It defines the cursor with
a name and the associated SELECT statement.
2.) OPEN :- It is used to allocate memory for the cursor and make it easy to fetch
the rows returned by the SQL statements into it.
CURSOR ATTRIBUTES : -
Both Implicit cursor and the explicit cursor has certain attributes that can be
accessed. These are as follows –
%FOUND - It returns the Boolean result 'TRUE' if the most recent fetch operation
fetched a record successfully, else it will return FALSE.
%NOTFOUND - This works oppositely to %FOUND it will return 'TRUE' if the most
recent fetch operation could not able to fetch any record.
%ISOPEN - It returns Boolean result 'TRUE' if the given cursor is already opened,
else it returns 'FALSE'
%ROWCOUNT - It returns the numerical value. It gives the actual count of records that
got affected by the DML activity.