Traditional application development languages cannot deal with result tables without some kind of intermediary mechanism because SQL is a set-oriented language. The intermediary mechanism is the cursor.
A cursor is a pointer that the application program uses to move through a result table.
You declare a cursor for a SELECT request, and then open the named cursor. The act of opening the cursor executes the SQL request.
You use the FETCH... INTO... statement to individually fetch and write the rows into host variables. The application can then use the host variables to do computations.
Teradata Preprocessor2 uses cursors to mark or tag the first row accessed by an SQL query. Preprocessor2 then increments the cursor as needed.
SQL stored procedures use:
- Cursors to fetch one result row at a time and then to execute SQL and SQL control statements as required for each row. Local variables or parameters from the stored procedure can be used for computations.
- Result set cursors to return the result of a SELECT statement executed in the stored procedure to the caller of the stored procedure or the client application.