开发者

Can I create a trigger that involves a cursor on a table that the trigger is not made for?

For example if I have a trigger for table employee. I want to create a cursor loop from the table department. Then I want to take the attribute and insert it into the table company. I'm guessing the answer is no, because I get a runtime error that says table department cannot be found, but is there any way around this that gets the same effect?

CREATE TRIGGER myTrigger AFTER INSERT
ORDE开发者_运维百科R 1 ON dba.employee
REFERENCING NEW AS newRow
FOR EACH ROW
BEGIN
    FOR myloop AS getIDCursor INSENSITIVE CURSOR FOR SELECT department_id FROM department
    DO 
       INSERT INTO company (...) VALUES (...);
    END FOR
END


Why are you using SQL like a procedural language? Just do:

INSERT INTO company SELECT department_id FROM department

No need for loops.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜