Passing arguments from DB2 to external functions
DB2® provides storage for all parameters that are passed to a user-defined function (UDF). Therefore, parameters are passed to an external function by address.
This is the normal parameter passing method for programs. For service programs, ensure that the parameters are defined correctly in the function code.
When defining and using the parameters in the UDF, care should be taken to ensure that no more storage is referenced for a given parameter than is defined for that parameter. The parameters are all stored in the same space and exceeding a given parameter's storage space can overwrite another parameter's value. This, in turn, can cause the function to see invalid input data or cause the value returned to the database to be invalid.
There are several supported parameter styles available to external UDFs. For the most part, the styles differ in how many parameters are passed to the external program or service program.
- Parameter style SQL
The SQL parameter style conforms to the industry standard SQL. This parameter style can be used only with scalar user-defined functions (UDFs).
- Parameter style DB2SQL
With the DB2SQL parameter style, the same parameters and the same order of parameters are passed to an external program or a service program as with the SQL parameter style. However, DB2SQL allows additional optional parameters to be passed as well.
- Parameter style GENERAL
With the GENERAL parameter style, the parameters are passed to an external service program just as they are specified in the CREATE FUNCTION statement. This parameter style can be used only with scalar user-defined functions (UDFs).
- Parameter style GENERAL WITH NULLS
The GENERAL WITH NULLS parameter style can be used only with scalar user-defined functions (UDFs).
- Parameter style DB2GENERAL
The DB2GENERAL parameter style is used by Java™ user-defined functions (UDFs).
- Parameter style Java
The Java parameter style is the style specified by the SQLJ Part 1: SQL Routines standard.
Parent topic:
Writing UDFs as external functions