The C/C++ code for defining a scalar user-defined function includes four mandatory pieces:
extfnapiv3.h – Inclusion of the UDF interface definition header file.
_evaluate_extfn – An evaluation function. All evaluation functions take two arguments:
An instance of the scalar UDF context structure that is unique to each usage of a UDF that contains a set of callback function pointers, and a pointer where a UDF can store UDF-specific data.
A pointer to a data structure that allows access to the argument values and to the result value through the supplied callbacks.
a_v3_extfn_scalar – An instance of the scalar UDF descriptor structure that contains a pointer to the evaluation function.
Descriptor function – Returns a pointer to the scalar UDF descriptor structure.
_start_extfn – An initialization function generally invoked once per SQL usage. If supplied, you must also place a pointer to this function into the scalar UDF descriptor structure. All initialization functions are defined to take one argument, a pointer to the scalar UDF context structure that is unique to each usage of a UDF. The context structure passed is the same one that is passed to the evaluation routine.
_finish_extfn – A shutdown function generally invoked once per SQL usage. If supplied, a pointer to this function must also be placed into the scalar UDF descriptor structure. All shutdown functions are defined to take one argument, a pointer to the scalar UDF context structure that is unique to each usage of a UDF. The context structure passed is the same one that is passed to the evaluation routine.