oracle 调用操作系统脚本 EXTPROC

在oracle 中执行操作系统命令,操作系统脚本(scheduler  program可以容易的实现)


extproc (External Procedures )配置:

一般的数据库都自动配置了这些东西,extproc 默认是oracle 用户,要使用非oracle用户需要单独的配置这些文件:

参见官方文档:

Note 1018659.102 How to Run External Procedures as a Non-oracle User

配置的官方文档:

EXTPROC: Setting up the Callback Demonstration [ID 47484.1]

Listener.ora

The following additions should be made to your SQL*Net configuration
files:

  Listener.ora
  ~~~~~~~~~~~~

  Add a 'callout' entry to the SID_LIST_LISTENER parameter. The example
  here uses a TCP/IP connection but other protocols could be used
  PROVIDED that the EXTPROC process being called resides on the SAME
  physical machine as the database.

  For example:

      SID_LIST_LISTENER=
       (SID_LIST=
        (SID_DESC= (SID_NAME=callout)
                  (ORACLE_HOME=/supp/app/oracle/product/8.0.3)
                  (PROGRAM=/supp/app/oracle/product/8.0.3/bin/extproc)
        )
       )

  Notes: 

     - ORACLE_HOME should be the correct ORACLE_HOME for the instance.
     - PROGRAM should be set to $ORACLE_HOME/bin/extproc, since this is the
agent process that runs the external procedures.
     - The SID_NAME should NOT clash with a valid database SID.
 
  Tnsnames.ora
  ~~~~~~~~~~~~

  Add an alias for 'extproc_connection_data'.  This is the hard-coded
  name used to locate the External Procedure Agent.  Point the 'ADDRESS'
  to an address where the listener is listening.

  For example:

      extproc_connection_data=
       (DESCRIPTION =
    (ADDRESS = (PROTOCOL=tcp)(host=uksn95)(port=1522))
    (CONNECT_DATA=(SID=callout))
       )
 
 
  Note:

     - If you have 'NAMES.DEFAULT_DOMAIN' set in your SQLNET.ORA,
       then the TNSNAMES entry should be 'EXTPROC_CONNECTION_DATA.DOMAIN'.

       For example:

          sqlnet.ora:       NAMES.DEFAULT_DOMAIN=world
          tnsnames.ora:     EXTPROC_CONNECTION_DATA.WORLD=(...)

       The 'SID' used here should be the same as the SID set in LISTENER.ORA.


在oracle 官方文档有专门的例子:

Note 168065.1 How to Call a UNIX Shell Script. From PL/SQL Using External Procedures :

From the Oracle server machine:

1. Create a file for the external procedure code:

shell.c:
#include
#include
#include

void sh(char *);
void sh( char  *cmd )
{
        int num;
        num = system(cmd);
}

2. Compile and link the C code into a shared library:

make -f $ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_nocallback SHARED_LIBNAME=shell.so BJS=shell.o


Log into SQL*Plus to perform. the remaining steps.


3. Define the shared library in Oracle:

CREATE LIBRARY shell_lib IS '/shell.so';
/


4. Create the PL/SQL wrapper procedure:

CREATE OR REPLACE PROCEDURE shell (cmd IN CHAR)
AS EXTERNAL
   NAME "sh"
   LIBRARY shell_lib
   LANGUAGE C
PARAMETERS (
    cmd STRING);
/

5. Call a shell script.:

SQL> exec shell(/bin/'sh /myscripts/myscript.sh');

PL/SQL procedure successfully completed.

关于这个东西的一些说明:

extproc :
一:用途:
1. 使用pl/sql 调用c语言程序
2. 访问操作系统的共享程序库或动态链接库(dll)
二:确定安装
   执行: $ORACLE_HOME/bin/extproc
    显示:
        Oracle Corporation --- TUESDAY   AUG 16 2011 14:20:55.230
        Heterogeneous Agent Release 10.2.0.3.0 - 64bit Production
三:调用过程
plsql调用c过程的步骤:
1,用户进程调用一个plsql程序
2,服务器进程执行plsql子程序,查询别名库。(别名库是数据库里的一个对象,
用来描述一个外部函数所在的动态链接库的路径和名称。通过别名库,从而可以知道被调用的外部函数在哪个文件里。)
3,PL/SQL将对外部函数的调用请求发送给监听器。
4, 监听器生成一个extproc进程,该进程专门用来处理对外部函数的调用。
   每个session都会生成一个属于该session的extproc进程,  并且在整个session生命周期里,
      extproc进程会一直存在。
5,进程负责将别名库所指定的动态链接库文件加载到内存。
6,进程执行指定的外部函数,并将结果返回给服务器进程,进而返回给用户进程。

 

主要参考:

Master Note For PL/SQL External Procedures [ID 1136408.1]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21634752/viewspace-705008/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21634752/viewspace-705008/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值