dbms_job not executing jobs at regular interval inside trigger

时间:2016-09-01 06:16:05

标签: sql oracle plsql oracle11g triggers

Create or replace TRIGGER AFT_INSERT_TMP_TBL
AFTER INSERT ON TMP_TBL
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE 

V_SQL   VARCHAR2(1000);
A_NAME  VARCHAR2(100);
l_jobno NUMBER;
BEGIN
A_NAME:='ANY_NAME';

dbms_job.submit( l_jobno,
                 'myProc',
                 sysdate + interval '2' minute,
                 'sysdate + interval ''2'' minute' );
END AFT_INSERT_TMP_TBL;

I have a trigger which creates a dbms_job and the job will run for every two minutes after then. The problem I am getting is the trigger executes multiple times and the job sits in the queue as seen in USER_JOBS and never gets executed. I cannot write commit inside the trigger, so how to get this job up and running in every two minutes.

2 个答案:

答案 0 :(得分:1)

Oracle正在做正确的事情 - 在提交行之前不会触发作业。

在这种情况下你想发生什么?

insert into tmp_tbl (col1) values ('Wrong value');
rollback;

我猜你不希望触发任何工作?

答案 1 :(得分:-1)

You can create a procedure that submits the job. Then the trigger can call the procedure.