Sullivan Market

a web based full-circle development system



My SQL Tutorials - Cursor Processing

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
Select UserName
From Users_Table,
Where Last_Name equals "Smith"
Order By First_Name;

Open CursorSmith;

Fetch CursorSmith
Into :First_Name;

Back To SQL Tutorials

©2012 SullivanMarket.com