Cursor
Cursor
Definition :-
A cursor is a temporary work area to execute SQL statements and to store the processed
information. (This work area is private to SQL’s operations and is called a CURSOR).
To handle a result set inside the stored procedure, stored functions and triggers, we can use a
cursor.
It is a way to retrieve data from a database and process it one row at a time, rather than
retrieving all the data at once and then processing it. (It can hold more than one row, but can
process only one row at a time).
When a SELECT statement is executed, the result set is stored in a cursor in SQL, which can then
be used to fetch and process the rows one at a time. The cursor acts as a pointer to the current row
in the result set, allowing the developer to move forward and backwards through the result set.
In SQL, there are two types of cursors:
Implicit cursors: These are automatically created by the database management system (DBMS)
when a SELECT statement is executed without the use of an explicit cursor.
Explicit cursors: These are created by the developer using the DECLARE CURSOR statement.
They are used to retrieve and process data.
Cursors in SQL are commonly used in PL/SQL and T-SQL to fetch and process data from the
database, but they can also be used in other languages that have an SQL interface.
Diagram illustrates how cursor works :-
NO