• Cursor is a handle (or pointer), to the context area.PL/SQL program can control the context area using Cursor. • SELECT statement should return only one row at a time in previous PL/SQL programs. • We use the idea of Cursor to handle the above problem. Even if your query returns only a single row, you might still decide to use an explicit cursor.
In PL/SQL, you can refer to the most recent implicit cursor as the SQL cursor, which always has attributes such as %FOUND, %ISOPEN, %NOTFOUND, and %ROWCOUNT.In PL/SQL, the SELECT list may contain PL/SQL variables, expressions, and even functions as well as host language bind variables ( Fetching from a Cursor Syntax: FETCH cursor_name INTO record_or_variable_list; e.g., FETCH employee_cur INTO employee_rec; e.g.,.FETCH employee_cur INTO name, age, salary • When you fetch into a list of variables or record, the number of variables and types in the record must match the number of expressions in the SELECT list of the cursor. For more information, see "Querying Data with PL/SQL".Syntax sql cursor ::= Description of the illustration sql_Keyword and Parameter Description %BULK_ROWCOUNT A composite attribute designed for use with the .It is created on a SELECT Statement which returns more than one row. General Syntax for creating a cursor is as given below: In the above example we are creating a cursor ‘emp_cur’ on a query which returns the records of all the employees with salary greater than 5000. When the data is fetched it is copied to the record or variables and the logical pointer moves to the next row and it becomes the current row.Here ‘emp_tbl’ in the table which contains records of all the employees. On every fetch statement, the pointer moves to the next row.2) Accessing the records in the cursor: Once the cursor is created in the declaration section we can access the cursor in the execution section of the PL/SQL program. If you want to fetch after the last row, the program will throw an error.When there is more than one row in a cursor we can use loops along with explicit cursor attributes to fetch all the records.Points to remember while fetching a row: · We can fetch the rows in a cursor to a PL/SQL Record or a list of variables created in the PL/SQL Block.· If you are fetching a cursor to a PL/SQL Record, the record should have the same structure as the cursor.