Vous êtes sur la page 1sur 4

An external procedure is a procedure called from another program, but written in a different language.

An example would be a PL/SQL program calling one or more C routines that are required to perform special-purpose processing. When an application calls an external procedure, Oracle Database starts an external procedure agent named extproc. Using the network connection established by Oracle Database, the application passes the following information to the agent: DLL or shared library name External procedure name Any parameters The agent then loads the DLL or the shared library, and runs the external procedure and passes back to the application any values returned by the external procedure.

The agent must reside on the same computer as the application making the external procedure call.

The agent then loads the DLL or the shared library, and runs the external procedure and passes back to the application any values returned by the external procedure. The agent must reside on the same computer as the application making the external procedure call. When you use the default configuration for external procedures, the extproc agent is spawned directly by Oracle Database. There are no configuration changes required for either listener.ora or tnsnames.ora. When the default configuration for external procedures is used, define the environment variables to be used by external procedures in the extproc.ora file located in the $ORACLE_HOME/hs/admin directory on UNIX operating systems or the %ORACLE_HOME%\hs\admin directory on Windows. You can change the default configuration for external procedures and have your extproc agent spawned by the listener similar to prior releases of Oracle Database. To do this, modify the default configuration, as follows: 1. Configure and run a separate or existing listener to serve external procedures. Oracle Net Configuration Assistant configures a listener to accept connections for both the database and external procedures during a database server installation. In addition, Oracle Net Configuration Assistant configures a net service name for the external procedures in tnsnames.ora file on the database server. The external procedure agent will only be able to load DLLS from the bin or lib directories in the ORACLE_HOME.

1.

Example 13-1shows a sample configuration in the listener.ora file.

Example 13-1 listener.ora File with a Sample External Procedure Setup

LISTENER= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcp)(HOST=sale-server) (PORT=1521)) (ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))) SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=sales.us.example.com) (ORACLE_HOME=/oracle) (SID_NAME=sales)) (SID_DESC= (SID_NAME=plsextproc) (ORACLE_HOME=/oracle) (PROGRAM=extproc)))
Example 13-2shows a sample configuration in the tnsnames.ora file.

Example 13-2 tnsnames.ora File a Sample External Procedure Setup

EXTPROC_CONNECTION_DATA= (DESCRIPTION= (ADDRESS=(PROTOCOL=ipc)(KEY=extproc)) (CONNECT_DATA= (SID=plsextproc)))

PL/SQL external procedures enable you to write C procedure calls as PL/SQL bodies. These C procedures are callable directly from PL/SQL, and from SQL through PL/SQL procedure calls. The database provides a special-purpose interface, the call specification, that lets you call external procedures from other languages. While this service is designed for intercommunication between SQL, PL/SQL, C, and Java, it is accessible from any base language that can call these languages. For example, your procedure can be written in a language other than Java or C and still be usable by SQL or PL/SQL, as long as your procedure is callable by C.

One way to load Java programs is to use the CREATE JAVAstatement, which you can execute interactively from SQL*Plus. When implicitly called by the CREATE JAVAstatement, the Java Virtual Machine (JVM)] library manager loads Java binaries (.classfiles) and resources from local

BFILEs or LOBcolumns into RDBMS libunits

Suppose a compiled Java class is stored in the operating system file /home/java/bin/Agent.class. Create a class libunitin schema username from file Agent.class as follows: 1. Connect to the database as SYSTEM and grant the user username the CREATE ANY DIRECTORY privilege. 2. Connect to the database as username and create a directory object on the server's file system:

CREATE DIRECTORY Bfile_dir AS '/home/java/bin';


The name of the directory object is an alias for the directory path leading to Agent.class. 3. Create the class libunit:

4. CREATE JAVA CLASS USING BFILE (Bfile_dir, 'Agent.class');


The name of the libunitis derived from the name of the class.

EXTERNAL PROCEDURE C

When an application calls an external C procedure, Oracle Database or Oracle Listener starts the external procedure agent, extproc. Using the network connection established by Oracle Database or Oracle Listener, the application passes the following information to extproc:

Name of DLL or shared library Name of external procedure Any parameters for the external procedure

Then extprocloads the DLL or the shared library, runs the external procedure, and passes any values that the external procedure returns back to the application. The application and extprocmust reside on the same computer.

Example: Locating a Call Specification in a PL/SQL Package


CREATE OR REPLACE PACKAGE Demo_pack AUTHID DEFINER AS

PROCEDURE plsToC_demoExternal_proc (x PLS_INTEGER, y VARCHAR2, z DATE) AS LANGUAGE C NAME "C_demoExternal" LIBRARY SomeLib WITH CONTEXT PARAMETERS(CONTEXT, x INT, y STRING, z OCIDATE); END;

Example: Locating a Call Specification in a PL/SQL Package Body


CREATE OR REPLACE PACKAGE Demo_pack AUTHID CURRENT_USER AS PROCEDURE plsToC_demoExternal_proc(x PLS_INTEGER, y VARCHAR2, z DATE); END; CREATE OR REPLACE PACKAGE BODY Demo_pack SQL_NAME_RESOLVE CURRENT_USER AS PROCEDURE plsToC_demoExternal_proc (x PLS_INTEGER, y VARCHAR2, z DATE) AS LANGUAGE JAVA NAME 'pkg1.class4.methodProc1(int,java.lang.String,java.sql.Date)' ; END;

Vous aimerez peut-être aussi