create a file which has name "shell.c"
content of shell.c file
------------------------------------
#include
#include
#include
void sh(char *);
void sh( char *cmd )
{
int num;
num = system(cmd);
}
------------------------------------
--create object file
[oracle@host01 lib]$ gcc -fPIC -g -c -Wall shell.c
--create shared library file
[oracle@host01 lib]$ gcc -shared -o shell.so shell.o
modify parameter in $ORACLE_HOME/hs/admin/extproc.ora file
SET EXTPROC_DLLS=/home/oracle/lib/shell.so
--create lib and procedure for test
CREATE OR REPLACE LIBRARY SHELL_LIB
IS '/home/oracle/lib/shell.so'
/
CREATE OR REPLACE PROCEDURE "SHELL" (cmd IN char)
as external
name "sh"
library shell_lib
language C
parameters (cmd string);
/
SQL> exec shell('/bin/pwd > /home/oracle/lib/aa.txt');
output file looks like
[oracle@host01 lib]$ more aa.txt
/u01/oracle/11.2.0.3/dbs
ORA-28575: unable to open RPC connection
to external procedure agent