如果插入或更新了行BLOCKED = 0:
,我会触发删除数据create or replace trigger DATA_SOURCE_delete_blocked
after insert or update
on DATA_SOURCE
FOR EACH ROW
WHEN (new.BLOCKED=0)
BEGIN
DELETE FROM DATA_SOURCE WHERE DATA_SOURCE_ID=:NEW.DATA_SOURCE_ID;
end;
它适用于插入(至少数据没有写入,但可能有错误),但是对于更新,它不会因为变异错误而起作用:
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.
在插入/更新后是否有任何简单的方法可以在创建视图时删除行?
更新: 解决了compaund触发器的问题:
CREATE OR REPLACE TRIGGER DATA_SOURCE_DELETE_BLOCKED
FOR INSERT OR UPDATE ON DATA_SOURCE when (new.BLOCKED=0)
COMPOUND TRIGGER
ID1 NUMBER;
AFTER EACH ROW IS
BEGIN
ID1:=:NEW.DATA_SOURCE_ID;
END AFTER EACH ROW;
AFTER STATEMENT IS
BEGIN
DELETE FROM DATA_SOURCE WHERE DATA_SOURCE_ID=ID1;
END AFTER STATEMENT;
END DATA_SOURCE_DELETE_BLOCKED;