Cursor Idiosyncrasies
-
The optional
FOR UPDATEclause can be included in theSELECTstatement, but its absence does not prevent successful execution of a positioned update or delete -
Care should be taken to ensure that the names of declared cursors do not conflict with any names used subsequently in statements for
AS CURSORclauses -
If the cursor is needed only to walk the result set, it is nearly always easier and less error-prone to use a
FOR SELECTstatement with theAS CURSORclause.Declared cursors must be explicitly opened, used to fetch data, and closed.The context variableROW_COUNThas to be checked after each fetch and, if its value is zero, the loop has to be terminated.AFOR SELECTstatement does this automatically.Nevertheless, declared cursors provide a high level of control over sequential events and allow several cursors to be managed in parallel.
-
The
SELECTstatement may contain parameters. For instance:SELECT NAME || :SFX FROM NAMES WHERE NUMBER = :NUMEach parameter has to have been declared beforehand as a PSQL variable, or as input or output parameters.When the cursor is opened, the parameter is assigned the current value of the variable.
|
Warning
|
Unstable Variables and Cursors
If the value of the PSQL variable used in the Note particularly that the behaviour may depend on the query plan, specifically on the indexes being used.Currently, there are no strict rules for this behaviour, and this may change in future versions of Firebird. |