Search⌘ K
AI Features

Cursors

Explore the use of cursors within MySQL stored procedures to iterate through query results sequentially. Learn to declare variables, handle NOT FOUND conditions, and manage cursor operations such as opening, fetching rows, and closing. This lesson helps you implement and control cursors to process data efficiently within stored procedures.

We'll cover the following...

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 ...