在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 :
关于这个东西的一些说明:
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博客 ” ,链接:https://blog.itpub.net/21634752/viewspace-705008/ ,如需转载,请注明出处,否则将追究法律责任。