Download PL/SQL User's Guide and Reference, Release 8.0

Transcript
Calling an External Procedure
WITH CONTEXT
Specifies that a context pointer will be passed to the external procedure. The
context data structure is opaque to the external procedure but is available to service
routines called by the external procedure. For more information, see “Using the
WITH CONTEXT Clause” on page 10-16.
PARAMETERS
Specifies the positions and datatypes of parameters passed to the external
procedure. It can also specify parameter properties such as current length and
maximum length, and the preferred parameter passing method (by value or by
reference). For more information, see “Using the PARAMETERS Clause” on
page 10-12.
An Example
Assume that C routine c_gcd, which finds the greatest common divisor of two
numbers, is stored in DLL utils.so and that you have EXECUTE privileges on
alias library c_utils. The C prototype for c_gcd follows:
int c_gcd(int x_val, int y_val);
In the following example, you write a PL/SQL stand-alone function named gcd
that registers C routine c_gcd as an external function:
CREATE FUNCTION gcd (
-- find greatest common divisor of x and y
x BINARY_INTEGER,
y BINARY_INTEGER)
RETURN BINARY_INTEGER AS EXTERNAL
LIBRARY c_utils
NAME "c_gcd" -- quotes preserve lower case
LANGUAGE C;
Calling an External Procedure
You do not call an external procedure directly. Instead, you call the PL/SQL
subprogram that registered the external procedure. Such calls, which you code in
the usual way, can appear in
■
anonymous blocks
■
stand-alone and packaged subprograms
■
methods of an object type
External Procedures 10-5