对于分配,我正在尝试使用 Oracle 将主键触发到其外键进行级联更新。我不能在外键中使用级联更新。
下面是我生成相应错误的代码:
CREATE or REPLACE trigger TR_PRODNO_FK_UPDATE
/* trigger executes BEFORE
an UPDATE of prodNo on the Product table */
before update of prodNo on tbProduct
/* trigger executes for each ROW */
for each row
/* begins a PL/SQL Block */
begin
/* update prodNo on tbProduct */
UPDATE tbProduct a
SET a.prodNo = :new.prodNo
WHERE :old.prodNo = a.prodNo;
/* update the prodNo on tbComponent */
UPDATE tbComponent b
SET b.prodNo = :new.prodNo
WHERE :old.prodNo = b.prodNo;
/* send message to output */
dbms_output.put_line (
'*** Related rows in the
PRODUCT and COMPONENT table updated - TR_PRODNO_FK_UPDATE trigger');
end TR_PRODNO_FK_UPDATE;
/
UPDATE tbProduct
SET prodNo = '104'
WHERE prodNo = '100';
这里出了什么问题?有任何想法吗?