插入触发错误后

时间:2016-07-15 14:29:45

标签: oracle plsql

我尝试创建一个触发器,在插入表后插入另一个表中的多行。

这是我的触发器

<input type="button" id="click" value="Click me" />
<input type="button" id="remove" value="Remove listener" />

但在构建触发器时,我得到 CREATE OR REPLACE TRIGGER my_trigger AFTER INSERT ON a_table FOR EACH ROW DECLARE cursor parts is SELECT id, part FROM parts WHERE :new.id = parts.id; BEGIN FOR part in parts LOOP INSERT INTO parts_tb2 (id, part, name) VALUES (part.id, part.part, :new.NAME); END LOOP; END my_trigger;

我错过了哪里;?我在某个地方错过了某个关键字吗?

1 个答案:

答案 0 :(得分:0)

CREATE OR REPLACE TRIGGER my_trigger
AFTER INSERT ON a_table
FOR EACH ROW
    DECLARE
    CURSOR c_parts IS
        SELECT id, part FROM parts
        WHERE :new.id = id;
    BEGIN
        FOR v_part in c_parts LOOP
            INSERT INTO parts_tb2 (id, part, name)
                VALUES (v_part.id, v_part.part, :new.NAME);
        END LOOP;
END my_trigger;