Comparison and casting functions for structured types

Db2® automatically creates functions that cast values between the reference type and its representation type, in both directions.

The CREATE TYPE statement has an optional CAST WITH clause that allows you to choose the names of these two cast functions. By default, the names of the cast functions are the same as the names of the structured type and its reference representation type. For example, the CREATE TYPE Person_t statement automatically creates functions with the following format:

   CREATE FUNCTION VARCHAR(REF(Person_t))
      RETURNS VARCHAR
Db2 also creates the function that does the inverse operation:
   CREATE FUNCTION Person_t(VARCHAR(13))
      RETURNS REF(Person_t)

You can use these cast functions whenever you need to insert a new value into the typed table or when you want to compare a reference value to another value.

Db2 also creates functions that let you compare reference types using the following comparison operators: =, <>, <, <=, >, and >=.