Oracle creates a memory area, also called context area, to process SQL statements. Cursor is a pointer to this memory area and this memory (context) area is controlled by the cursor.
The size of the cursor is flexible according to its data. Oracle keeps some predefined space in the main memory to open the cursor, so the size of the cursor is limited. Whenever a query is run, the cursor works.
A Cursor is fetch all rows of a table one by one selected by the SQL statements. When I have need to check all rows of a table one by one or update data of that table then here we use Cursor.
Types of Cursor:
There are two types of Cursor,
1- Implicit Cursor.
2- Explicit Cursor.
Implicit cursor: Whenever the SQL statement is executed, the implicit cursor is automatically created by Oracle (when there is no explicit cursor for the statement.)
'Programmers cannot control the implicit cursor and the information contained in it”. The cursor that is opened by Oracle for internal processing is called implicit cursor.
Explicit cursor: Explicit cursor is user-defined. Through Explicit cursor, we can have more control in the memory (context) area.
The cursor is used when some records from a table are accessed in a PL/SQL code block. SQL queries are used to declare this cursor.
Both these types of cursor have four common attributes, which are as follows:-
%isopen:- Returns true value if the cursor is open otherwise return false.
%found:- Returns true value if records are fetched successfully otherwise return false.
%notfound:- Returns true value if the records are not fetched successfully otherwise return false.
%Rowcount:- It returns the number of records processed.
Create a Cursor:
DECLARE Variables;
DECLARE Cursor_Name CURSOR FOR
SQL Query
OPEN Cursor_Name
FETCH NEXT FROM Cursor_name INTO
VariableName
WHILE @@FETCH_STATUS=0
Process the Record
FETCH NEXT FROM Cursor_Name INTO VariableName
CLOSE Cursor_Name
DEALLOCATE Cursor_Name
Ex- Lets have take a database table ‘Student’
The following SQL statement is used cursor to retrieve the student ID and Name from above table.
The following SQL statement is used to create a Cursor to fetch the distinct record from two table and show all records into a single form.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL Cursor :
Oracle creates a memory area, also called context area, to process SQL statements. Cursor is a pointer to this memory area and this memory (context) area is controlled by the cursor.
The size of the cursor is flexible according to its data. Oracle keeps some predefined space in the main memory to open the cursor, so the size of the cursor is limited. Whenever a query is run, the cursor works.
A Cursor is fetch all rows of a table one by one selected by the SQL statements. When I have need to check all rows of a table one by one or update data of that table then here we use Cursor.
Types of Cursor:
There are two types of Cursor,
1- Implicit Cursor.
2- Explicit Cursor.
Implicit cursor: Whenever the SQL statement is executed, the implicit cursor is automatically created by Oracle (when there is no explicit cursor for the statement.)
'Programmers cannot control the implicit cursor and the information contained in it”. The cursor that is opened by Oracle for internal processing is called implicit cursor.
Explicit cursor: Explicit cursor is user-defined. Through Explicit cursor, we can have more control in the memory (context) area.
The cursor is used when some records from a table are accessed in a PL/SQL code block. SQL queries are used to declare this cursor.
Both these types of cursor have four common attributes, which are as follows:-
%isopen:- Returns true value if the cursor is open otherwise return false.
%found:- Returns true value if records are fetched successfully otherwise return false.
%notfound:- Returns true value if the records are not fetched successfully otherwise return false.
%Rowcount:- It returns the number of records processed.
Create a Cursor:
Ex- Lets have take a database table ‘Student’
The following SQL statement is used cursor to retrieve the student ID and Name from above table.
The following SQL statement is used to create a Cursor to fetch the distinct record from two table and show all records into a single form.