21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PSQL statements<br />

Description: Fetches the next data row from a cursor's result set and stores the column values in PSQL variables.<br />

Syntax:<br />

Notes:<br />

FETCH cursorname INTO [:]varname [, [:]varname ...];<br />

• The ROW_COUNT context variable will be 1 if the fetch returned a data row and 0 if the end of the set has<br />

been reached.<br />

• You can do a positioned UPDATE or DELETE on the fetched row with the WHERE CURRENT OF clause.<br />

Example: See DECLARE ... CURSOR.<br />

Available in: PSQL<br />

Added in: 1.5<br />

FOR EXECUTE STATEMENT ... DO<br />

Description: See EXECUTE STATEMENT :: Any number of data rows returned.<br />

Available in: PSQL<br />

FOR SELECT ... INTO ... DO<br />

Description: Executes a SELECT statement and retrieves the result set. In each iteration of the loop, the field<br />

values of the current row are copied into local variables. Adding an AS CURSOR clause enables positioned<br />

deletes and updates. FOR SELECT statements may be nested.<br />

Syntax:<br />

FOR <br />

INTO [, ...]<br />

[AS CURSOR name]<br />

DO<br />

<br />

::= A valid SELECT statement.<br />

::= A PSQL variable name, optionally preceded by “:”<br />

::= A single statement or a block of PSQL code.<br />

• The SELECT statement may contain named SQL parameters, like in “select name || :sfx<br />

from names where number = :num”. Each parameter must be a PSQL variable that has been<br />

declared previously (this includes any in/out params of the PSQL module).<br />

• Caution! If the value of a PSQL variable that is used in the SELECT statement changes during<br />

execution of the loop, the statement may (but will not always) be re-evaluated for the remaining<br />

rows. In general, this situation should be avoided. If you really need this behaviour, test your code<br />

104

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!