The diagram for DECLARE refers to this section.
To declare a select cursor for a collection variable, include the Collection- Derived Table segment with the SELECT statement that you associate with the collection cursor. A select cursor allows you to select one or more elements from the collection variable. (For a description of SELECT syntax and usage, see SELECT.)
When you declare a select cursor for a collection variable, the DECLARE statement has the following restrictions:
The select cursor is an update cursor.
The select cursor must be a sequential cursor.
In addition, the SELECT statement that you associate with the collection cursor has the following restrictions:
These columns cannot use the following syntax:
database@server:table.column --INVALID SYNTAX
You cannot specify an input parameter (the question-mark ( ? ) symbol) for the collection variable. Likewise you cannot use the virtual table format of the Collection-Derived Table segment.
A collection cursor that includes a SELECT statement with the Collection- Derived Table clause provides access to the elements in a collection variable.
To modify elements of the collection variable, declare the select cursor as an update cursor with the FOR UPDATE keywords. You can then use the WHERE CURRENT OF clause of the DELETE and UPDATE statements to delete or update elements of the collection.
Once the collection variable contains the correct elements, use the UPDATE or INSERT statement to save the contents of the collection variable in the actual collection column (SET, MULTISET, or LIST).
This DECLARE statement declares a select cursor for a collection variable:
EXEC SQL BEGIN DECLARE SECTION; client collection set(integer not null) a_set; EXEC SQL END DECLARE SECTION; ... EXEC SQL declare set_curs cursor for select * from table(:a_set);
For an extended code example that uses a collection cursor for a SELECT statement, see Fetching from a Collection Cursor (IDS).
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]