Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
SQL is inherently a set-based language. However, certain complex algorithms (such as iteratively calculating interest compounded across variable daily brackets or calling external webhooks per customer) require row-by-row iteration.
In MySQL stored programs, row-by-row iteration is accomplished using a Cursor.
DECLARE: Declares the cursor and associates it with a specific SELECT query.OPEN: Initializes the cursor and executes the query to materialize the result set.FETCH: Retrieves the current row into local variables and advances the internal pointer to the next row.CLOSE: Releases the cursor and frees its allocated memory.Because a cursor does not know how many rows exist in advance, you must declare a CONTINUE HANDLER FOR NOT FOUND to signal when the cursor reaches the end of data:
MySQL cursors possess three immutable characteristics:
UPDATE ... WHERE CURRENT OF).Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Deterministic vs Non-Deterministic Functions | Stored Functions vs Stored Procedures Architecture |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.