Selecting from a Row Variable (ESQL/C)
The SELECT statement can include the Collection-Derived Table segment to select one or more fields from a row variable.
About this task
The Collection-Derived Table segment identifies the row variable from which to select the fields. For more information, see Collection-Derived Table.
To select fields:Procedure
Results
The INTO clause can specify a host variable to hold a field value selected from the row variable.
EXEC SQL BEGIN DECLARE SECTION;
ROW (x INT, y INT, length FLOAT, width FLOAT) myrect;
double rect_width;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT rect INTO :myrect FROM rectangles
WHERE area = 200;
EXEC SQL SELECT width INTO :rect_width FROM table(:myrect);
- No expressions are allowed in the select list of the Projection clause.
- ROW columns cannot be in a WHERE clause comparison condition.
- The Projection clause must be an asterisk ( * ) if the row-type contains fields of opaque, distinct, or built-in data types.
- Columns listed in the Projection clause can have only unqualified names. They cannot use the syntax database@server:table.column.
- The following clauses are not allowed: GROUP BY, HAVING, INTO TEMP, ORDER BY, and WHERE.
- The FROM clause has no provisions to do a join.
You can modify the row variable with the Collection-Derived Table segment of the UPDATE statements. (The INSERT and DELETE statements do not support a row variable in the Collection-Derived Table segment.)
- To update the ROW column in the table with the row variable, use an UPDATE statement on a table or view name and specify the row variable in the SET clause. For more information, see Updating ROW-Type Columns.
- To insert a row into a ROW column, use the INSERT statement on a table or view and specify the row variable in the VALUES clause. See Inserting Values into ROW-Type Columns.
For examples of how to use SPL row variables, see the HCL OneDB™ Guide to SQL: Tutorial. For information on using row variables, see the discussion of complex data types in the HCL OneDB ESQL/C Programmer's Manual.