Initializing a Foreign Function
To initialize a foreign function:
- Use ORA_FFI.LOAD_LIBRARY to obtain a library handle to the dynamic library
containing the foreign function. You must provide the name and location of
the dynamic library.
- Use ORA_FFI.REGISTER_FUNCTION to obtain a function handle to the foreign
function. You must provide the library handle and name of the foreign function.
- Use ORA_FFI.REGISTER_PARAMETER to register the foreign function parameter
types. For each parameter, provide the function handle to identify the foreign
function and a corresponding PL/SQL equivalent parameter type. You must register
parameters in the order they appear in the foreign function prototype.
- Use ORA_FFI.REGISTER_RETURN to register the foreign function return type.
You must provide the function handle to identify the foreign function and
a corresponding PL/SQL equivalent return type.
Initializing a foreign function: Example
Here is an example of initializing a foreign function:
PACKAGE BODY calc IS
BEGIN
/*
This example shows how to initialize the foreign function
int ADD(int X, int Y) that is contained in the dynamic
library CALC.DLL;
*/
lh_calc := ora_ffi.load_library('c:/mathlib/', 'calc.dll');
fh_add := ora_ffi.register_function(lh_calc,'add',
ora_ffi.C_STD);
ora_ffi.register_return(fh_add,ORA_FFI.C_INT);
ora_ffi.register_parameter(fh_add,ORA_FFI.C_INT);
ora_ffi.register_parameter(fh_add,ORA_FFI.C_INT);
END;
Related topic
About the PL/SQL interface