This article introduces the term "Cursors" in Oracle.
Cursors
In Oracle, Cursors are the temporary private working area where queries are processed. It is used to access the result set present in memory. A cursor contains the information on a select statement and the rows of the data accessed by it.
Syntax
- CURSOR cursor_name
- IS
- SELECT_statement;
Syntax of cursor with parameter
- CURSOR cursor_name (parameter_list)
- IS
- SELECT_statement;
Example
- CURSOR cur (order_id_in IN varchar2)
- IS
- SELECT order_no
- FROM orders_table1
- WHERE order_id = order_id_in;
Features of Cursors
Cursors consist of the following two features:
- It allows us to fetch and process rows returned by the select statement.
- A cursor is named so that it can be referenced.
Normally, cursors are divided into the two parts:
- Implicit Cursors
- Explicit Cursors

Implicit Cursor
An Implicit Cursor is also known as a predefined cursor. Every time when an Oracle query is executed an implicit cursor is automatically declared and used by Oracle. Implicit cursors are managed by the Oracle Engine itself. In this process the user is not at all aware of the implicit cursor since it cannot tell us how many rows were affected by an update, the numbers of rows updated are returned by SQL%ROWCOUNT. It is used to process INSERT, UPDATE, DELETE and SELECT INTO statements where the operations like DECLARE, OPEN, FETCH, and CLOSE are automatically performed by Oracle. Implicit cursors are used in the statement that returns only one row and if more than one row is returned an error will occur.
SQL%ROWCOUNT can be used as follows:
SQL%ROWCOUNT can be used as follows:
- SET SERVEROUTPUT ON
- BEGIN
- UPDATE Students
- SET Stud_name = 'Varun'
- WHERE Cust_name LIKE 'Varun%';
- DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
- END;
Implicit Cursor Attributes
| Attributes | Working |
| % IS OPEN | Cursor opens automatically via Oracle Engine and returns the value = true in an open condition otherwise return false. |
| %FOUND | If one or more than one row is processed and affects the INSERT, UPDATE, DELETE and SELECT statement operation, then the cursor returns the value = true and otherwise false. |
| %NOTFOUND | If no row is processed and did not affect the INSERT, UPDATE, DELETE and SELECT statement operation, then the cursor returns the value = true and otherwise false. |
| %ROWCOUNT | Returns the number of rows processed or affected by the INSERT, UPDATE, DELETE and SELECT statement. |
- Provide less programmatic control
- More vulnerable to data errors
- Less efficient than explicit cursor
Example using attributes for the following employee_Info table:
| Emp_id | Emp_name | Designation | Salary |
| 1001 | Rahul | Project Manager | 80K |
| 1002 | Karan | Developer | 40K |
| 1003 | Seema | Sr. Developer | 50K |
| 1004 | Shreya | Developer | 38k |
| 1005 | Reet | Tech Lead | 55K |
| 1006 | Gaurav | Tech Lead | 62K |

Adeyemi AdetayoPosted May 24, 2021, 3:10 PM
I was trying to import from my database but was receiving an invalid cursor error. But i do spool before without the encountering the error