/*************************************************************************** * extproc.c Frank Naude, (c) 1999 * Call operating system commands from PL/SQL. www.orafaq.org *************************************************************************** * Setup: * 1. Compile this program: cc -G extproc.c -o extproc.so * 2. SQL> create library shell_lib as '/app/oracle/local/extproc.so'; * 3. SQL> create or replace function sysrun (syscomm in varchar2) * return binary_integer * as language C -- Use "as external" in older releases * name "sysrun" * library shell_lib * parameters(syscomm string); * / * 4. Run $ORACLE_HOME/bin/extproc to make sure it is executable. * 5. Define TNSNAMES.ORA entry: * EXTPROC_CONNECTION_DATA = (DESCRIPTION = * (ADDRESS=(PROTOCOL=IPC)(KEY=extproc)) * (CONNECT_DATA=(SID=extproc))) * 6. Define LISTENER.ORA entry and reload listener: * EXTERNAL_PROCEDURE_LISTENER = * (ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc))) * SID_LIST_EXTERNAL_PROCEDURE_LISTENER = * (SID_LIST=(SID_DESC=(SID_NAME=extproc) * (ORACLE_HOME=/app/oracle/ORA815)(PROGRAM=extproc))) * 7. Execure an OS command: * PL/SQL> declare * rc number; * begin * rc := sysrun('/bin/ls -l'); * dbms_output.put_line('Return Code='||rc); * end; * / * * Notes: * 1. Rewrite this program unsing C Piping to capture command output. * See popen() function. * 2. Steps to make the Oracle provided examples: * $ cd $ORACLE_HOME/plsql/demo * $ make -f demo_plsql.mk extproc.so * */ int sysrun(char *command) { return system(command); }