0% found this document useful (0 votes)
10 views

Cursors

Cursors are memory areas in SQL that allow for the retrieval and processing of data one row at a time, with two main types: implicit and explicit cursors. Implicit cursors are automatically created by Oracle for DML statements, while explicit cursors are defined by the user for queries returning multiple rows. Cursor attributes provide information about the state of the cursor, and a cursor for loop simplifies the handling of cursors by managing opening, fetching, and closing automatically.

Uploaded by

seemahpatil2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Cursors

Cursors are memory areas in SQL that allow for the retrieval and processing of data one row at a time, with two main types: implicit and explicit cursors. Implicit cursors are automatically created by Oracle for DML statements, while explicit cursors are defined by the user for queries returning multiple rows. Cursor attributes provide information about the state of the cursor, and a cursor for loop simplifies the handling of cursors by managing opening, fetching, and closing automatically.

Uploaded by

seemahpatil2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Cursors

Cursors are memory areas that allow


You to allocate an area of memory and access the
information retrieved from sql statement.

Types of cursors

1. Implicit cursor
2. Explicit cursor
Two Important Features
1. Cursors allow you to fetch and
process rows returned by a select
statement,one row at a time.

2. Cursor is named so that it can be


referenced.
Cursors
1. Implicit cursor is automatically declared by oracle every time
an sql statement is executed.the user will not be aware of this
happening.

2 . Explicit cursor is defined by the program for any query that


returns more than one row of data.
Implicit Cursor
1. Cursor is automatically associated with every DML
statement.

2. All Update and delete statements have cursors that


identify the set of rows that will be affected by
operation.
Explicit Cursor

1. Declaring the cursor :- This initializes the cursor into


memory.

2. Opening cursor :- The previously declared cursor can


now be opened;memory is alloted.

3. Fetching the cursor :- previously declared and opened


cursor can now retrieve data;this is the process of
fetching the cursor.

4. Closing the cursor :- Previously declared,opened, and


fetched cursor must now be closed to release memory
allocation.
Cursor Attributes
Cursor Attribute Syntax Explanation
%NOTFOUND Cursorname%NOTFOUND Returns true if the
previous fetch didn’t
return row and false if it
did.
%FOUND Cursorname%FOUND Returns true if the
previous fetch returned a
row ,and false if it did
not.
%ROWCOUNT Cursorname%ROWCOUNT Records fetched from
cursor at that point in
time.
%ISOPEN Cursorname%ISOPEN Returns true if cursor is
open,false if it is not.
Cursors

declare
vname varchar2(20);
begin
select fname into vname from student11;
dbms_output.put_line('name is ' || vname);
end;
Cursors
ORA-01422:
exact fetch returns more than requested
number of rows
Cursors
Declare
Cursor student is Select fname from student11;
Vname student11.fname%type;
Begin
Open student;
Loop
Fetch student into vname;
Exit when student%notfound;
Dbms_output.put_line('name is' || vname);
End loop;
Close student;
end;
Cursors
Output

name is anit
name is SUNIL

PL/SQL procedure successfully completed.


Cursor For Loop
1. There is an alternative method of handling cursors.it is
called cursor For loop.
2. When using cursor for loop,the process of
opening,fetching, and closing is handled implicitly.
3. This makes the blocks much simpler to code and easier
to maintain.

You might also like