创建触发器

时间:2009-11-13 15:31:41

标签: triggers

我有这个触发器

procedure CASE_A  
as  
UPDATE table1 SET field1 = (SELECT bus FROM view1 WHERE table1.document = view1.document)  
end;

下面的触发器应该执行上面的过程CASE_A(Case_A应该将值放入field1)

CREATE OR REPLACE TRIGGER "CASE_A" AFTER INSERT ON "TABLE1" FOR EACH ROW  
BEGIN  
CASE_A;
END;

但是,它没有这样做。

1 个答案:

答案 0 :(得分:0)

你做错了,至少假设这是甲骨文。

最好这样做:

CREATE OR REPLACE TRIGGER "CASE_A" BEFORE INSERT ON "TABLE1" FOR EACH ROW  
BEGIN  
    SELECT bus INTO :new.field1 FROM view1 WHERE :new.document = view1.document;
END;

编辑:由于view1依赖于table1,我们需要做更多...(阅读评论以获取更多信息)

CREATE OR REPLACE TRIGGER "CASE_A" BEFORE INSERT ON "TABLE1" FOR EACH ROW  
BEGIN  
    SELECT sum(FUNCTION_CASEA(b.DUE, b.RETD)) INTO :new.field1
      FROM table2
      WHERE table1.document = table2.document 
        AND table1.field1 = table2.branch;
END;