An OUT parameter
An OUT parameter is a routine argument that is always passed by reference to the C user-defined function.
A C user-defined function can use an OUT parameter to return a value indirectly. For the OUT parameter, the database server allocates storage for an opaque data type or for a data type that you can pass by value (but not for a varying-length data type) and passes a pointer to that storage to the UDR. Multiple OUT parameters are supported and they are allowed anywhere in the argument list, not just at the end.
- Declare the OUT parameter as a pointer to the appropriate data
type
The size of the OUT parameter must be the size of an MI_DATUM structure. The passing mechanism for the parameter must be pass by reference regardless of the data type that you pass back.
- Set the argument-value array of the MI_FPARAM structure
to NULL.
The UDR will update the argument-value array.
mi_integer out_test(
mi_lvarchar *doc,
mi_lvarchar *query,
mi_integer *weight, /* OUT parameter */
MI_FPARAM *fp)
{
/* Set the value of the OUT parameter */
*weight = 100;
/* Set the value of the OUT parameter to "not null" */
mi_fp_setargisnull(fp, 2, MI_FALSE);
return MI_TRUE;
}
CREATE FUNCTION out_test(doc LVARCHAR,
query VARCHAR(120),
OUT weight INTEGER)
RETURNING BOOLEAN
EXTERNAL NAME '/usr/udrs/udrs.so'
LANGUAGE C;