Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > SELECT >

Selecting from a Row Variable (IDS, ESQL/C)

The SELECT statement can include the Collection-Derived-Table segment to select one or more fields from a row variable. 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
  1. Create a row variable in your ESQL/C program.
  2. Optionally, fill the row variable with field values.

    You can select a ROW-type column into the row variable with the SELECT statement (without the Collection-Derived-Table segment). Alternatively, you can insert field values into the row variable with the UPDATE statement and the Collection-Derived-Table segment.

  3. Select row fields from the row variable with the SELECT statement and the Collection-Derived-Table segment.
  4. Once the row variable contains the correct field values, you can use the INSERT or UPDATE statement on a table or view name to save the contents of the row variable in a named or unnamed row column.

The INTO clause can specify a host variable to hold a field value selected from the row variable.

The type of the host variable must be compatible with that of the field. For example, this code fragment puts the width field value into the rect_width host 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);

The SELECT statement on a row variable has the following restrictions:

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.)

The row variable stores the fields of the row. It has no intrinsic connection, however, with a database column. Once the row variable contains the correct field values, you must then save the variable into the ROW column with one of the following SQL statements:

For examples of how to use SPL row variables, see the IBM Informix Guide to SQL: Tutorial. For information on using ESQL/C row variables, see the discussion of complex data types in the IBM Informix ESQL/C Programmer's Manual.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]