在Oracle触发器代码中使用'exec'并失败

时间:2017-03-10 02:16:20

标签: linux oracle shell

我尝试创建Oracle触发器,在表插入或更新后,触摸Linux主机中的文件。

所以我创建了一个像这样的shell脚本:

#!/bin/bash
sqlplus $oam <<EOF
spool /ocs/ocsrun/other/gx_working/select.txt;
@/ocs/ocsrun/other/gx_working/select.sql;
spool off;
exit;
EOF
touch  /export/home/oracle/shell/a.txt

并修改权限:

chmod 777 test1.sh

然后我使用sys登录oracle并创建一个这样的调度程序作业:

SQL>  exec DBMS_SCHEDULER.CREATE_JOB(job_name=>'test1',job_type=>'EXECUTABLE',job_action=>'/export/home/oracle/shell/test1.sh');
PL/SQL procedure successfully completed.

现在我想创建一个Oracle触发器并像这样调用此调度程序作业:

CREATE OR REPLACE TRIGGER MY_OAM_LOG
 AFTER INSERT OR UPDATE ON OCS_CHARGE_OFF_AUTOMATION
 FOR EACH ROW 
BEGIN
 DBMS_SCHEDULER.RUN_JOB(job_name=>'test1');
END;
/

当我更新此表时,错误如:

ERROR at line 1:
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or
directory
ORA-06512: at "SYS.DBMS_ISCHED", line 185
ORA-06512: at "SYS.DBMS_SCHEDULER", line 486
ORA-06512: at "OAM.MY_OAM_LOG", line 2
ORA-04088: error during execution of trigger 'OAM.MY_OAM_LOG'

我从管理员指南中搜索了一些文档,例如exapmle 27-5: http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/scheduse002.htm#i1032197

在我改变我的shell脚本之后

是错误相同的:

#!/bin/bash
export ORACLE_HOME=/opt/oracle/instantclient
export ORACLE_SID=ocsdb
sqlplus $oam <<EOF
spool /ocs/ocsrun/other/gx_working/select.txt;
@/ocs/ocsrun/other/gx_working/select.sql;
spool off;
exit;
EOF
touch  /export/home/oracle/shell/a.txt

shell能够独立运行,我该怎么兼对?plz

1 个答案:

答案 0 :(得分:0)

可能无法找到sqlplus命令,因为从Oracle数据库执行时,您错过了所有环境设置。因此,在脚本开头设置必要的路径,或输入sqlplus等命令的完整路径。