Once the function is selected, there are still possible reasons why the use of the function may not be permitted. Each function is defined to return a result with a specific data type. If this result data type is not compatible within the context in which the function is invoked, an error will occur. For example, given functions named STEP defined with different data types as the result:
STEP(SMALLINT) RETURNS CHAR(5) STEP(DOUBLE) RETURNS INTEGER
and the following function reference (where S is a SMALLINT column):
SELECT ... 3 +STEP(S)
then, because there is an exact match on argument type, the first STEP is chosen. An error occurs on the statement because the result type is CHAR(5) instead of a numeric type as required for an argument of the addition operator.
In cases where the arguments of the function invocation were not an exact match to the data types of the parameters of the selected function, the arguments are converted to the data type of the parameter at execution using the same rules as assignment to columns (see Assignments and comparisons). This includes the case where precision, scale, length, or CCSID differs between the argument and the parameter.
An error also occurs in the following examples:
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.