简体   繁体   English

Sql Oracle 12c触发器

[英]Sql Oracle 12c Trigger

I need some help. 我需要一些帮助。 I'm trying to create a Trigger that execute a procedure whenever insert, delete or update operations are done on a specific table. 我正在尝试创建一个触发器,只要在特定的表上执行插入,删除或更新操作,就执行该过程。 This is the trigger 这是触发器

CREATE OR REPLACE NONEDITIONABLE TRIGGER NQDI.GAV_TRG 
AFTER INSERT or UPDATE or DELETE ON D_GAV
FOR EACH ROW
BEGIN
    PRC_FILL_D_GAV(:old.report_name);
END;

Unofortunately, since the trigger starts before any commit has been done and I need to read from the same table, it gives me the 'D_GAV table is being modified can't be read' error. 不幸的是,由于触发器在任何提交完成之前就开始了,我需要从同一个表中读取,它给了我“正在修改D_GAV表无法读取”的错误。 Besides, the FOR EACH ROW makes the trigger start for every record changed, while I want the trigger to start only at the end, when every update, insert or delete has been committed, but I haven't find a way to preserve the :old.report_name while doing this. 此外, FOR EACH ROW使每个记录的触发器开始改变,而我希望触发器仅在结束时启动,每次更新,插入或删除都已提交,但我还没有找到保存的方法执行此操作时, old.report_name I know I could do what I want with an "up and running process", but I'd like to avoid that. 我知道我可以通过“正常运行的过程”做我想做的事,但我想避免这种情况。 Is there any other solution that I'm overlooking? 我还有其他解决方案吗?

You want a compound trigger . 你想要一个复合触发器 After each row event you insert the data into an array. 在每个行事件之后,您将数据插入到数组中。 And after the statement you loop through the data and call your procedure. 在声明之后,您循环访问数据并调用您的过程。

create or replace trigger nqdi.gav_trg
for insert or update or delete on d_gav compound trigger

  type type_table_of_gav is table of d_gav%rowtype;
  v_gavs type_table_of_gav := type_table_of_gav();

  after each row is
  begin
    v_gavs.extend(1);
    v_gavs(v_gavs.count).report_name := coalesce(:old.report_name, :new.report_name);
  end after each row;

  after statement is
  begin
    for i in 1 .. v_gavs.count loop
      prc_fill_d_gav(v_gavs(i).report_name);
    end loop;
  end after statement;

end gav_trg;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM