Update a collection of row types
To update a collection of ROW types, you can take these
steps:
- Declare a collection variable whose field data types match those of the ROW types in the collection.
- Set the individual fields of the collection variable to the correct data values for the ROW type.
- For each ROW type, update the entire row of the collection derived table using the collection variable.
The manager table in Define the manager table. has a column
named projects that contains a LIST of ROW types with the definition
that the following figure shows.
To access the ROW types in the LIST, declare a cursor
and select the LIST into a collection variable. After you retrieve
each ROW type value in the projects column, however, you cannot
update the pro_name or pro_members fields individually.
Instead, for each ROW value that needs to be updated in the collection,
you must replace the entire ROW with values from a collection variable
that include the new field values, as the following figure shows.
Before you can use a row-type variable in an SPL program,
you must initialize the row variable with a LET statement or a SELECT
INTO statement. The UPDATE statement nested in the FOREACH loop of
the previous figure sets the pro_name field of the row type
to the value supplied in the variable pro.
Tip: To
update a value in a SET in the pro_members field of the ROW
type, declare a cursor and use an UPDATE statement with a derived
column, as Update a collection element explains.