Distinct types as UDF or method parameters
The user-defined functions (UDFs) and methods can be defined with parameters that are distinct types or return distinct types result.
Procedure
You must explicitly cast distinct type arguments that originate
from host variables when they are used to call an UDFs or a method
that accepts distinct types parameters.
The explicit casting
is required by the database, which uses strong typing and to avoid
ambiguous results. The following example contains the CREATE statement
for the BOAT_COST UDF that accepts BOAT distinct type, which is defined
from a BLOB:
CREATE FUNCTION BOAT_COST (BOAT)
RETURNS INTEGER
...
In the following fragment of a C language application,
the host variable :ship
holds the BLOB value that
is passed to the BOAT_COST function: EXEC SQL BEGIN DECLARE SECTION;
SQL TYPE IS BLOB(150K) ship;
EXEC SQL END DECLARE SECTION;
Both of the following
statements correctly resolve to the BOAT_COST function because both
cast the
:ship
host variable to type BOAT: ... SELECT BOAT_COST (BOAT(:ship)) FROM ...
... SELECT BOAT_COST (CAST(:ship AS BOAT)) FROM ...
If there are multiple BOAT distinct types in the database, or BOAT UDFs in other schema, you must exercise care with your SQL path. Your results can otherwise be ambiguous.