Return multiple values
Unlike an SPL routine, a C user-defined function can directly return
at most one value. However, a user-defined function can return multiple
values when you use the following features together:
- An OUT parameter in the user-defined function
- A statement local variable (SLV) in the SQL statement that calls the user-defined function
OUT parameters and SLVs enable a user-defined function to return
a second value to the calling SQL statement.
Tip: This
section discusses the use of SLVs and OUT parameters in the context
of a C user-defined function. You cannot use SLVs and OUT parameters
in SPL functions. A user-defined procedure with an OUT parameter must
be called in the WHERE clause of an SQL statement. For general information
about how to use an OUT parameter, see the discussion of how to return
multiple values from external functions in the Informix® User-Defined Routines
and Data Types Developer's Guide.
An alternative to using an OUT parameter is an iterator function. This special-purpose user-defined function can return multiple values, one value per iteration of the function. For more information, see Write an iterator function.