Handle the external representation

Every opaque type has an internal and external representation. The internal representation is the internal structure that you define for the opaque type. (For more information, see The internal structure.) The external text representation is a character string that is a printable version of the opaque value. The opaque type might also have an external binary representation.

When you define an opaque type, you must supply support functions that convert between the internal and external representations of the opaque type:
  • The input function converts from external text representation to internal representation.
  • The output function converts from internal to the external text representation.

These support functions do not have to be named input and output, but they do have to perform the specified conversions. They should be reciprocal functions; that is, the input function should produce a value that the output function accepts as an argument and vice versa. For the database server to execute these support functions automatically, you must provide an implicit cast from LVARCHAR to the user-defined type that invokes the input function. Similarly, you must also provide an explicit cast from the UDT to LVARCHAR that invokes the output function.

The database server raises an error if it cannot find the proper support function to carry out a task. For example, if an application tries to INSERT a value in an external text format, the database server looks for a cast from LVARCHAR to the user-defined type. If that cast does not exist, the database server raises an error.

For your opaque data type to accept an external representation on nondefault locales, you must use the HCL® OneDB® GLS API in the input and output functions to access HCL OneDB locales from within these functions. For more information, see Handle locale-sensitive data (GLS).