POSITION | Teradata Vantage - POSITION - Advanced SQL Engine - Teradata Database

SQL Stored Procedures and Embedded SQL

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
xqq1557098602407.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

Positions a cursor to the beginning of the next statement or to the results of a specified statement.

Invocation

Executable.

Embedded SQL only.

Syntax

POSITION cursor_name
  [ TO
    { NEXT |
      [STATEMENT] { statement_number | [:] numeric_variable }
    }
  ]
cursor_name
The name of an open cursor other than an Insertion cursor.
statement_number
An integer numeric for the statement number to which positioning is desired.
numeric_variable
A host variable conforming to type INTEGER that represents the statement number to which positioning is desired. Use of a colon character is optional.

ANSI Compliance

POSITION is ANSI/ISO SQL:2011-compliant.

Authorization

None.

Rules

The cursor is repositioned before the first result row (if any) of the statement specified and SQLSTATE, SQLCODE and other SQLCA values are set.

With POSITION TO NEXT, the cursor is positioned to the next statement.

With POSITION TO STATEMENT, the cursor is positioned to the specified statement.

If the specified statement number does not exist (for example, TO STATEMENT 3 is coded, but the cursor controls only two statements), the following runtime exception occurs, leaving the position of the cursor undefined:
  • SQLCODE is set to -501
  • SQLSTATE is set to ‘24501’

The cursor can be positioned either forward or backward from the current statement and can be repositioned to a given statement as many times as the application requires.

For COBOL programs with multiple compile units, the cursor can only be positioned backward if a REWIND or POSITION TO STATEMENT occurs in the same compile unit as the declaration and the opening of the cursor.

POSITION is valid with any cursor except an insertion cursor.

The statement set found by the cursor is not re-executed, but the cursor position in the spool file is adjusted accordingly.

You cannot execute POSITION as a dynamic SQL statement.

Related Topics

For more information about: