Cursors - Advanced SQL Engine - Teradata Database

Database Introduction

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qia1556235689628.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1091
lifecycle
previous
Product Category
Teradata Vantageā„¢

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.