My SQL Tutorials - Cursor Processing
To retrieve data with SQL one row at a time you need to use cursor processing. Not all relational databases support this, but many do. Here I show this with DB2 and embedded SQL, which is SQL that is "embedded" in a program like COBOL, C, or Java. Cursor processing is done in several steps: 1. Define the rows you want to retrieve. This is called declaring the cursor. 2. Open the cursor. This activates the cursor and loads the data. Note that defining the cursor doesn't load data, opening the cursor does. 3. Fetch the data into host variables. 4. Close the cursor. Here is a example that explains Cursor Processing...
Declare CursorSmith Cursor for
Where Last_Name equals "Smith"
Order By First_Name;