Manage memory for rows

After you declare a row variable, recognizes the variable name. For typed row variables, also recognizes the associated data type. However, does not automatically allocate or deallocate memory for row variables. You must explicitly manage memory that is allocated to a row variable. To manage memory for both typed and untyped row host variables, use the following SQL statements:
  • The ALLOCATE ROW statement allocates memory for the specified row variable.

    This row variable can be a typed or untyped row. The ALLOCATE ROW statement sets SQLCODE (sqlca.sqlcode) to zero if the memory allocation was successful and a negative error code if the allocation failed.

  • The DEALLOCATE ROW statement deallocates or frees memory for a specified row variable.

    After you free the row variable with the DEALLOCATE ROW statement, you can reuse the row variable but you must allocate memory for it again. You might, for example, use an untyped row variable to store different row types in succession.

Important: does not implicitly deallocate memory that you allocate with the ALLOCATE ROW statement. You must explicitly perform memory deallocation with the DEALLOCATE ROW statement.
The following code fragment declares the a_name host variable as a typed row, allocates memory for this variable, then deallocates memory for this variable:
EXEC SQL BEGIN DECLARE SECTION;
   row (
      fname char(15), 
      mi char(2)
      lname char(15)
      ) a_name;
EXEC SQL END DECLARE SECTION;
;

EXEC SQL allocate row :a_name;
;

EXEC SQL deallocate row :a_name;

For syntax information for the ALLOCATE ROW and DEALLOCATE ROW statements, see their descriptions in the HCL OneDB™ Guide to SQL: Syntax.