Cursors
This lesson explores the concept of cursors which offer an efficient mechanism to process query results containing multiple rows.
Cursors
In the previous lesson on iterative processing we looped through a set of rows. Cursors is a kind of a loop which is used to traverse the rows returned by a query. Just as the cursor on the computer screen shows the current position, a database cursor also shows its current position in the result-set. Cursors can only be used in stored procedures, functions and triggers to loop through the results of a query one row at a time. Cursors have some properties which will be discussed next.
Cursors are read-only meaning they can only be used to view the result-set and not update it. They are non-scrollable meaning they can only show rows in the result-set in a sequential manner. It is not possible to view rows in a different order than the one returned by the query or to skip some rows to reach a specific row. MySQL cursors are asensitive meaning they point to the actual data in the ...