Creating a row data type

Creating a row data type is a prerequisite to creating a row variable.

Before you create a row data type:

This task can be done from any interface that supports the execution of the CREATE TYPE statement.

To create a row data type within a database, you must successfully execute the CREATE TYPE (ROW) statement from any Db2® interface that supports the execution of SQL statements.

  1. Formulate a CREATE TYPE (ROW) statement:
    1. Specify a name for the type.
    2. Specify the row field definition for the row by specifying a name and data type for each field in the row.
    The following is an example of how to create a row data type that can be associated with result sets with the same format as the empRow row data type:
    CREATE TYPE empRow AS ROW (name VARCHAR(128), id VARCHAR(8));
  2. Execute the CREATE TYPE statement from a supported Db2 interface.

If the CREATE TYPE statement executes successfully, the row data type is created in the database. If the statement does not execute successfully, verify the syntax of the statement and verify that the data type does not already exist.

Once the row data type is created, row variables can be declared based on this data type.