我有两个表:paper
和paperselection
。
在我的代码中,我想将rank
表中具有paper
属性大于4的任何纸张放入paperselection
表中
此后,我想做的是在将值插入papNo
表中之后,将主键(paper
)从该paperselection
移到paperselection
我在这里有两个触发器
---first trigger---
CREATE OR REPLACE TRIGGER paperselection_tr
BEFORE INSERT OR UPDATE OF Rank ON paper
FOR EACH ROW
BEGIN
IF :NEW.rank > 4
THEN insert into paperselection (Papno, journalno, title, pdate)
values (:old.papno, :new.journalno, :new.title, :new.pdate);
END IF;
END;
---second trigger----
CREATE OR REPLACE TRIGGER paperselection_tr2
After insert or update ON paperselection
FOR EACH ROW
BEGIN
update paperselection
set paperselection.papno = paper.papno
where paper.title = paperselection.title;
end;
由于表的设计原因,我无法将:old.papno
设置为:new.papno
。
但是它一直在提示我错误:
LINE/COL ERROR --------- ------------------------------------------------------------- 2/1 PL/SQL: SQL Statement ignored 4/7 PL/SQL: ORA-00904: "PAPER"."TITLE": invalid identifier Errors: check compiler log
答案 0 :(得分:0)
第二个触发器对paper
表一无所知,因为它触发了After insert or update ON paperselection
,并且因为您在其中没有对paper
表的进一步引用。
因此不喜欢这样:
set paperselection.papno = paper.papno
where paper.title = paperselection.title;
我认为你想要这个
---second trigger----
CREATE OR REPLACE TRIGGER paperselection_tr2
After insert or update ON paperselection
FOR EACH ROW
BEGIN
update paperselection
set paperselection.papno =
(SELECT paper.papno
FROM paper
WHERE paper.title = :new.title
);
end;
但是,只有在paperselection
中有重复的行时,这才是逻辑操作。