Initialize a row variable
To perform operations on existing fields in a row-type column, you must first initialize the row variable with the field values.
- Specify the row-column name in the select list of the SELECT statement.
- Specify the row host variable in the INTO clause of the SELECT statement.
- Specify the table or view name, not the collection-derived table clause, in the FROM clause of the SELECT statement.
EXEC SQL BEGIN DECLARE SECTION;
row (
x integer,
y integer,
length integer,
width integer
) a_rect;
EXEC SQL END DECLARE SECTION;
EXEC SQL allocate row :a_rect;
EXEC SQL select rectangle into :a_rect from tab_unmrow
where area = 1234;
When you use a typed row host variable, the data types of the row-type column (the field types) must be compatible with the corresponding data types of the typed row host variable. The SELECT statement in the preceding code fragment successfully retrieves the rectangle column because the a_rect host variable has the same field types as the rectangle column.
/* This SELECT generates an error */
EXEC SQL select emp_name into :a_rect from tab_nmrow;
EXEC SQL BEGIN DECLARE SECTION;
row an_untyped_row;
EXEC SQL END DECLARE SECTION;
EXEC SQL allocate row :an_untyped_row;
EXEC SQL select rectangle into :an_untyped row
from tab_unmrow
where area = 64;
⋮
EXEC SQL select emp_name into :an_untyped_row
from tab_nmrow
where row{'Tashi'} in (emp_name.fname);
Both SELECT statements in this code fragment can successfully retrieve row-type columns into the an_untyped_row host variable. However, Informix® ESQL/C does not perform type checking on an untyped row host variable because its elements do not have a predefined data type.
After you have initialized the row host variable, you can use the collection-derived table clause to select or update existing fields in the row. For more information, see the following sections.