FETCH SQL statement
Description
Fetches the row after the row on which Cursor | Procedure is
positioned.
Syntax
|
1 |
FETCH <span>Cursor</span> | <span>Procedure</span> INTO <span>HostVariableList</span>; |
|
Parameter |
Description |
|---|---|
|
Cursor or Procedure |
The name of the cursor or procedure from |
|
HostVariableList |
PowerScript variables into which data |
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.
Error 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
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:
|
1 |
int     Emp_num |
|
1 |
string   Emp_name |
|
1 |
FETCH Emp_cur INTO :Emp_num, :Emp_name ; |
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:
|
1 |
int     Emp_num |
|
1 |
string   Emp_name |
|
1 |
FETCH Emp_cur INTO :emp_num, :emp_name ; |
|
1 |
sle_emp_num.Text = string(Emp_num) |
|
1 |
sle_emp_name.Text = Emp_name |