Cursors
Cursors
Cursor is a pointer to memory location which is called as context area which contains the information necessary for processing, including the number of rows processed by the statement, a pointer to the parsed representation of the statement, and the active set which is the set of rows returned by the query. Cursor contains two parts Header Body Header includes cursor name, any parameters and the type of data being loaded. Body includes the select statement. Ex: Cursor c(dno in number) return dept%rowtype is select *from dept; In the above Header cursor c(dno in number) return dept%rowtype Body select *from dept CURSOR TYPES Implicit (SQL) Explicit Parameterized cursors REF cursors CURSOR STAGES Open Fetch Close
CURSOR DECLERATION Syntax: Cursor <cursor_name> is select statement; Ex: Cursor c is select *from dept; CURSOR LOOPS Simple loop While loop For loop
SIMPLE LOOP
Syntax: Loop Fetch <cursor_name> into <record_variable>; Exit when <cursor_name> % notfound; <statements>; End loop;