Because SQL is set-oriented, traditional application development languages need an intermediary mechanism for moving through a result table. The intermediary mechanism is a pointer called a cursor.
Declare a named cursor for a SELECT request and open the cursor. Opening the cursor executes the SQL request.
Use the FETCH INTO statement to individually fetch and write the rows into host variables. The application can then use the host variables in 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 for the following purposes:
- To fetch one result row at a time and then execute the SQL statements as required for each row.
Computations can use local variables or parameters from the stored procedure.
- To return the result of a SELECT statement executed in the stored procedure to the caller of the stored procedure or the client application.