What is a cursor in PL SQL
William Taylor
Published Mar 16, 2026
Cursors are used when the user needs to update records in a singleton fashion or in a row by row manner, in a database table. The Data that is stored in the Cursor is called the Active Data Set. Oracle DBMS has another predefined area in the main memory Set, within which the cursors are opened.
What is a cursor in Oracle PL SQL?
Cursors are used when the user needs to update records in a singleton fashion or in a row by row manner, in a database table. The Data that is stored in the Cursor is called the Active Data Set. Oracle DBMS has another predefined area in the main memory Set, within which the cursors are opened.
What is cursor and its types?
Cursor is a Temporary Memory or Temporary Work Station. It is Allocated by Database Server at the Time of Performing DML(Data Manipulation Language) operations on Table by User. Cursors are used to store Database Tables. There are 2 types of Cursors: Implicit Cursors, and Explicit Cursors.
What is cursor in SQL with example?
A SQL Server cursor is a set of T-SQL logic to loop over a predetermined number of rows one at a time. The purpose for the cursor may be to update one row at a time or perform an administrative process such as SQL Server database backups in a sequential manner.What is use of cursor in Oracle?
To execute a multi-row query, Oracle opens an unnamed work area that stores processing information. A cursor lets you name the work area, access the information, and process the rows individually. For more information, see “Querying Data with PL/SQL”.
How do you define cursor?
A cursor can be viewed as a pointer to one row in a set of rows. The cursor can only reference one row at a time, but can move to other rows of the result set as needed.
What is the use of cursor?
Cursors are used by database programmers to process individual rows returned by database system queries. Cursors enable manipulation of whole result sets at once. In this scenario, a cursor enables the sequential processing of rows in a result set.
How do I declare a cursor in SQL?
- DECLARE cursor_name CURSOR FOR select_statement; …
- OPEN cursor_name; …
- FETCH NEXT FROM cursor INTO variable_list; …
- WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM cursor_name; END; …
- CLOSE cursor_name; …
- DEALLOCATE cursor_name;
What is a cursor object in SQL?
A SQL cursor is a database object that retrieves data from result sets one row at a time. The cursor in SQL can be used when the data needs to be updated row by row. A SQL cursor is a database object that is used to retrieve data from a result set one row at a time.
What is cursor example?Oracle creates a memory area, known as the context area, for processing an SQL statement, which contains all the information needed for processing the statement; for example, the number of rows processed, etc. A cursor is a pointer to this context area. … A cursor holds the rows (one or more) returned by a SQL statement.
Article first time published onWhere is cursor used in SQL Server?
Cursor is a database object to retrieve data from a result set one row at a time, instead of the T-SQL commands that operate on all the rows in the result set at one time. We use a cursor when we need to update records in a database table in singleton fashion means row by row.
Is it good to use cursor in SQL?
Cursors could be used in some applications for serialized operations as shown in example above, but generally they should be avoided because they bring a negative impact on performance, especially when operating on a large sets of data.
How can I see the cursor in SQL?
- Declare the cursor in declaration section.
- Open the cursor in execution section.
- Fetch the cursor to retrieve data into PL/SQL variable.
- Close the cursor to release allocated memory.
What is cursor and index in SQL?
In SQL, a cursor can be defined as a tool used widely to define a particular set of results. This result can be a set of data rows. A cursor is basically used to solve complex logic and works on a row by row manner. Index, on the other hand, has the main function of retrieving data from tables much quicker.
What are the disadvantages of a cursor?
- Uses more resources because Each time you fetch a row from the cursor, it results in a network roundtrip.
- There are restrictions on the SELECT statements that can be used.
- Because of the round trips, performance and speed is slow.
What is difference between cursor and while loop?
Loop and cursor can be utilized in a circumstance to deal with row-based processing in T-SQL. … While SQL While loop is quicker than a cursor, reason found that cursor is defined by DECLARE CURSOR. Every emphasis of the loop will be executed inside system memory and consuming required server assets.
Why SQL cursor is bad?
But, when you open a cursor, you are basically loading those rows into memory and locking them, creating potential blocks. Then, as you cycle through the cursor, you are making changes to other tables and still keeping all of the memory and locks of the cursor open.
What is the difference between select and cursor in PL SQL?
CURSOR is mainly used to extract data in segments or chunks from the DB table. Conversely for the SELECT statement and its variants, data is directly copied into a data object in the ABAP memory.