Example of a cast function
- The int_to_float() function converts the int_type argument
to LVARCHAR with the inner cast:
CAST(int_arg AS LVARCHAR)
The output support function of the int_type opaque data type serves as the cast function for this inner cast. This output support function must be defined as part of the definition of the int_type opaque data type; it converts the internal format of int_type to its external (LVARCHAR) format.
- The int_to_float() function converts the LVARCHAR
value to float_type with the outer cast:
CAST((LVARCHAR value from step 1) AS float_type)
The input support function of the float_type opaque data type serves as the cast function for this outer cast. This input support function must be defined as part of the definition of the float_type opaque data type; it converts the external (LVARCHAR) format of float_type to its internal format.
For information about input and output support functions, refer to Locale-sensitive input and output support functions.
After you register the function as an explicit cast, the end user can invoke the function with the CAST AS keywords or with the :: cast operator to convert an int_type value to a float_type value. For the syntax of the CREATE FUNCTION and CREATE CAST statements, refer to the HCL OneDB™ Guide to SQL: Syntax.