FETCH

Description

Fetches the row after the row on which Cursor | Procedure is positioned.

Syntax

FETCH Cursor | Procedure INTO HostVariableList;

Parameter

Description

Cursor or Procedure

The name of the cursor or procedure from which you want to fetch a row

HostVariableList

PowerScript variables into which data values will be retrieved

Usage

The USING TransactionObject clause is not allowed with FETCH; the transaction object was specified in the statement that declared the cursor or procedure.

If your DBMS supports formats of FETCH other than the customary (and default) FETCH NEXT, you can specify FETCH FIRST, FETCH PRIOR, or FETCH LAST.

NoteError handling It is good practice to test the success/failure code after executing a FETCH statement. To see if the FETCH was successful, you can test SLQCode for a failure code. However, if nothing matches the WHERE clause and no rows are fetched, SQLCode is still set to 100. To make sure the fetch affected at least one row, check the SQLNRows property of the transaction object.

Examples

Example 1

Example 1 This statement fetches data retrieved by the SELECT clause in the declaration of the cursor named Emp_cur and puts it into Emp_num and Emp_name:

int     Emp_num

string   Emp_name

FETCH Emp_cur INTO :Emp_num, :Emp_name ;

Example 2

Example 2 If sle_emp_num and sle_emp_name are SingleLineEdits, these statements fetch from the cursor named Emp_cur, store the data in Emp_num and Emp_name, and then convert Emp_num from an integer to a string, and put them in sle_emp_num and sle_emp_name:

int     Emp_num

string   Emp_name

FETCH Emp_cur INTO :emp_num, :emp_name ;

sle_emp_num.Text = string(Emp_num)

sle_emp_name.Text = Emp_name