This section provides information about how to return subtype data to DB2®
Suppose you want to insert a structured type into a DB2 database from an application using the following syntax:
INSERT INTO person (Oid, Name, Address)
VALUES ('n', 'Norm', :hvaddr);
To run the INSERT statement for a structured type:
When the application containing the INSERT statement with a structured type is bound, DB2 for Linux, UNIX, and Windows looks for a TO SQL client transform. DB2 for Linux, UNIX, and Windows looks for the transform in the transform group client_group because that is the TRANSFORM GROUP specified at bind time in Step 6. DB2 for Linux, UNIX, and Windows finds the transform function it needs: stream_address, which is associated with the root type Address_t in Step 5.
stream_address is a SQL-bodied function, defined in Step 4, so it has no stated dependency on any additional transform function. For input parameters, stream_address accepts VARCHAR(150), which corresponds to the application host variable :hvaddr. stream_address returns a value that is both of the correct root type, Address_t, and of the correct dynamic type.
stream_address parses the VARCHAR(150) input parameter for a substring that names the dynamic type: in this case, either 'Address_t' or 'US_addr_t'. stream_address then invokes the corresponding external UDF to parse the VARCHAR(150) and returns an object of the specified type. There are two client_to_address() UDFs, one to return each possible type. These UDFs are defined in Step 3. Each UDF takes the input VARCHAR(150), and internally constructs the attributes of the appropriate structured type, thus returning the structured type.
To return the structured types, each UDF needs a TO SQL transform function to construct the output attribute values into an instance of the structured type. The CREATE FUNCTION statements in Step 3 name the TRANSFORM GROUP that contains the transforms.
The SQL-bodied transform functions from Step 1, and the associations with the transform groups from Step 2, are named in the CREATE FUNCTION statements of Step 3.