Chapter 19
Stepping through a Dataset with Cursors
In This Chapter
Specifying cursor scope with the DECLARE statement
Opening a cursor
Fetching data one row at a time
Closing a cursor
A major incompatibility between SQL and the most popular application development languages is that SQL operates on the data of an entire set of table rows at a time, whereas the procedural languages operate on only a single row at a time. A cursor enables SQL to retrieve (or update, or delete) a single row at a time so that you can use SQL in combination with an application written in any of the popular languages.
A cursor is like a pointer that locates a specific table row. When a cursor is active, you can SELECT
, UPDATE
, or DELETE
the row at which the cursor is pointing.
Cursors are valuable if you want to retrieve selected rows from a table, check their contents, and perform different operations based on those contents. SQL can’t perform this sequence of operations by itself. SQL can retrieve the rows, but procedural languages are better at making decisions based on field contents. Cursors enable ...
Get SQL For Dummies, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.