在插入 oracle 之后延迟触发器调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3315927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delaying the trigger invocation after an insert oracle
提问by jsrg1
Is there a way to do this?. I found adding,
有没有办法做到这一点?。我发现添加,
DBMS_LOCK.sleep()
to the beginning of the trigger code by googling, but it blocks the insert itself from happening. I would like to insert the data but the trigger should be fired only after an arbitrary delay. Thanks.
通过谷歌搜索到触发代码的开头,但它阻止了插入本身的发生。我想插入数据,但触发器只能在任意延迟后触发。谢谢。
回答by Tony Andrews
It would help if we knew whyyou want this delay, and what the trigger is supposed to do afterthe delay. However, one possibility is to use the DBMS_JOBpackage in the trigger to create a job that runs at a time a little after the insert. For example:
如果我们知道您为什么需要这个延迟,以及延迟之后触发器应该做什么,那将会有所帮助。但是,一种可能性是在触发器中使用DBMS_JOB包来创建一个在插入后一次运行的作业。例如:
create trigger trg
after insert on tab
for each row
declare
jl_ob number;
begin
dbms_job.submit
( job => l_job
, what => 'myproc(:new.id);'
, next_date => sysdate+1/24/60 -- One minute later
);
end;
Alternatively, the trigger could insert a row into a special table, and a DBMS_JOB that runs on a schedule e.g. every 10 minutes could process rows in the table that are more than X minutes old.
或者,触发器可以将一行插入到一个特殊的表中,并且一个按计划运行的 DBMS_JOB 例如每 10 分钟可以处理表中超过 X 分钟的行。