Specifying OUT Parameters for User-Defined Routines

When you register a user-defined routine of HCL OneDB™, you can use the OUT keyword to specify that any parameter in the list is an OUT parameter. Each OUT parameter corresponds to a value the routine returns indirectly, through a pointer. The value that the routine returns through the pointer is an extra value, in addition to any values that it returns explicitly.

After you have registered a user-defined function that has one or more OUT parameters, you can use the function with a statement-local variable (SLV) in a SELECT statement. (For information about statement-local variables, see Statement-Local Variable Expressions.)

If you specify any OUT parameters, and you use HCL OneDB-style parameters, the arguments are passed to the OUT parameters by reference. The OUT parameters are not significant in determining the routine signature.

For example, the following declaration of a C user-defined function allows you to return an extra value through the y parameter:
int my_func( int x, int *y );
Register the C function with a CREATE FUNCTION statement similar to this:
CREATE FUNCTION my_func( x INT, OUT y INT )
   RETURNING INT
   EXTERNAL NAME "/usr/lib/local_site.so"
   LANGUAGE C
END FUNCTION; 
In the next example, this Java™ method returns an extra value by passing an array:
public static String allVarchar(String arg1, String[] arg2)
throws SQLException
{ 
arg2[0] = arg1;
return arg1; 
}
To register this as a UDF, use a statement similar to the following example:
CREATE FUNCTION all_varchar(VARCHAR(10), OUT VARCHAR(7)) 
   RETURNING VARCHAR(7)
   WITH (class = "jvp")
   EXTERNAL NAME 'informix.testclasses.jlm.Param.allVarchar(java.lang.String, 
   java.lang.String[ ])'
   LANGUAGE JAVA;