执行触发器等待修改同一表的事件时出错

时间:2015-09-11 16:43:28

标签: sql oracle triggers

我创建了一个触发器:当删除表值时,它会在事件发生的同一个表上执行更新。这意味着我需要一个临时表来执行此触发器?

SQL Developer(Oracle)中的错误:

  

原因:触发器(或在此语句中引用的用户定义的plsql函数)试图查看(或修改)表格,正在被触发它的语句修改。

     

操作:重写触发器(或函数),使其不读取que表。

create or replace
TRIGGER "trigger_name"
AFTER DELETE ON table1 FOR EACH ROW

BEGIN
 MERGE INTO table1 t
 USING ( SELECT rowid rid, row_number() OVER (PARTITION BY column_pearson order by column_age) rn FROM table1) u
 ON ( t.rowid = u.rid )
 WHEN MATCHED THEN UPDATE SET t.column2 = u.rn;

 END;

- 使用复合触发器 - 同名错误

create or replace
trigger "name_trigger"
for delete on table1

COMPOUND TRIGGER

AFTER STATEMENT IS
    BEGIN
    MERGE INTO table1
    USING ( SELECT rowid rid, row_number() OVER (PARTITION BY column_pearson order by column_age rn FROM table1) u
    ON ( t.rowid = u.rid )
    WHEN MATCHED THEN UPDATE SET t.column2 = u.rn;
    END AFTER STATEMENT
END name_trigger

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm

0 个答案:

没有答案