Reading a line from a result set with SQL FETCH

Application

SQL FETCH reads a row from the result set. The values of the individual cells are stored by the control in the bound Q parameters. The transaction is defined through the HANDLE to be specified, and the row is defined by the INDEX.

SQL FETCH takes all of the columns into consideration that contain the SELECT instruction (SQL command SQL EXECUTE).

Requirements

  • Code number 555343
  • Table exists
  • Appropriate table name
  • The names of tables and table columns must start with a letter and must not contain an arithmetic operator (e.g., +). Due to SQL commands, these characters can cause problems when data are input or read.

Description of function

Black arrows and associated syntax indicate internal processes of SQL FETCH. The gray arrows and associated syntax do not directly belong to the SQL FETCH command.

The control shows in the defined variable whether the read operation was successful (0) or incorrect (1).

Input

11 SQL FETCH Q1 HANDLE Q5 INDEX 5 IGNORE UNBOUND UNDEFINE MISSING

; Read out result of transaction Q5 line 5

The NC function includes the following syntax elements:

Syntax element

Meaning

SQL FETCH

Syntax initiator for the FETCH SQL command

Q/QL/QR or Q REF

Variable in which the control stores the result

HANDLE

Q parameter with identification of the transaction

INDEX

Row number within the result set as a number or variable

If not specified, the control accesses line 0.

Optional syntax element

IGNORE UNBOUND

For the machine manufacturer only

Optional syntax element

UNDEFINE MISSING

For the machine manufacturer only

Optional syntax element

Example

Transfer line number in the Q parameter

11 SQL BIND Q881 "Tab_Example.Position_Nr"

12 SQL BIND Q882 "Tab_Example.Measure_X"

13 SQL BIND Q883 "Tab_Example.Measure_Y"

14 SQL BIND Q884 "Tab_Example.Measure_Z"

* - ...

21 SQL Q5 "SELECT Position_Nr,Measure_X,Measure_Y, Measure_Z FROM Tab_Example"

* - ...

31 SQL FETCH Q1 HANDLE Q5 INDEX+Q2