DB2 Version 10.1 for Linux, UNIX, and Windows

Structure arrays

You can use structure arrays for FETCH INTO statements that are non-dynamic, when you set the precompiler option COMPATIBILITY_MODE to ORA.

A structure array can be used to store multiple column data in a structure form when a FETCH INTO statement is run.

In one FETCH INTO statement, the maximum number of records that can be retrieved is the cardinality of the array that is declared. If more rows are available after the first fetch, you can repeat the FETCH INTO statement to obtain the next set of rows.

The total number of rows that are successfully fetched is stored in the sqlca.sqlerrd[2] field.

In the following example, a structure array is used for a FETCH INTO statement:
// Declare structure array with cardinality of 3.
EXEC SQL BEGIN DECLARE SECTION;
	struct MyStruct
	{
		int c1;
		char c2[11];
	} MyStructVar[3];
EXEC SQL DECLARE cur CURSOR FOR
	SELECT empno, lastname FROM employee;
EXEC SQL END DECLARE SECTION;
...
// MyStrutVar is a structure array for host variables
EXEC SQL FETCH cur INTO :MyStructVar;

Restrictions with the structure array support

The use of the structure array in embedded SQL applications is subject to the following restrictions:
  • Structure arrays are supported by C or C++ embedded SQL applications that connect to DB2® for Linux, UNIX, and Windows servers.
  • Structure arrays must be declared in the DECLARE SECTION with exact size of the array elements (cardinality).
  • Specific array element cannot be specified in a SQL statement.
  • When structure array is specified, only one structure array can be declared in an embedded SQL application.
  • You cannot create a structure array within another structure array (for example, nested structure arrays).
  • Maximum size of array element (cardinality) is 32672.
  • The following C and C++ data types are not supported for use with structure arrays:
    • BLOB
    • BLOB file reference
    • BLOB locator variable
    • CLOB
    • CLOB file reference
    • CLOB locator variable
    • User-defined data type
    • XML