Determining Which Cast to Apply

The database server uses the following rules to determine which cast to apply in a particular situation:
  • To compare two built-in types, the database server automatically invokes the appropriate built-in casts.
  • The database server applies only one implicit cast per operand. If two or more casts are required to convert the operand to the specified type, the user must explicitly invoke the additional casts.

    In the following example, the literal value 5.55 is implicitly cast to DECIMAL, and is then explicitly cast to MONEY, and finally to yen:

    CREATE DISTINCT TYPE yen AS MONEY
    . . .
    INSERT INTO currency_tab
       VALUES (5.55::MONEY::yen)
  • To compare a distinct type to its source type, the user must explicitly cast one type to the other.
  • To compare a distinct type to a type other than its source, the database server looks for an implicit cast between the source type and the specified type.

    If neither cast is registered, the user must invoke an explicit cast between the distinct type and the specified type. If this cast is not registered, the database server automatically invokes a cast from the source type to the specified type.

    If none of these casts is defined, the comparison fails.

  • To compare an opaque type to a built-in type, the user must explicitly cast the opaque type to a data type that the database server understands (such as LVARCHAR, SENDRECV, IMPEXP, or IMPEXPBIN). The database server then invokes built-in casts to convert the results to the specified built-in type.
  • To compare two opaque types, the user must explicitly cast one opaque type to a form that the database server understands (such as LVARCHAR, SENDRECV, IMPEXP, or IMPEXPBIN) and then explicitly cast this type to the second opaque type.

For information about casting and the BOOLEAN, BSON, JSON, IMPEXP, IMPEXPBIN, LVARCHAR, and SENDRECV built-in opaque data types, see HCL OneDB™ User-Defined Routines and Data Types Developer's Guide.