Return the value

For execution of a user-defined function, the routine manager returns any resulting value to the query executor when execution is complete. When the routine manager returns the value from a user-defined function, it passes this value as an MI_DATUM value.

As with routine arguments, the passing mechanism that the routine manager uses depends on the size of the return-value data type, as follows:
  • The routine manager passes most return values by reference; that is, it passes a pointer to the actual return value.

    If the return value has a data type whose size is greater than the size of the MI_DATUM data type, the routine manager passes the return value by reference because it cannot fit the actual value onto the stack. The routine manager allocates the memory for these pass-by-reference return values with a PER_ROUTINE duration.

  • The routine manager passes a few special types of return values by value; that is, the MI_DATUM structure contains the actual return value.

    If the return value is a data type whose size is less than or equal to the size of the MI_DATUM data type, the routine manager passes the return value back by value because it can fit the actual value onto the stack. Types of values that fit in an MI_DATUM structure (Passed by value) lists the data types that the routine manager passes by value.

Tip: For a particular return-value data type, you can determine from its type descriptor whether it is passed by reference or passed by value with the mi_type_byvalue() function.

The routine manager determines information about the return value (such as whether it is an SQL NULL value) from the MI_FPARAM structure of the UDR. For information about how to code routine return values, see Define a return value.