我正在尝试创建一个触发器,每次客户下订单时,都会将客户的盘旋增加.04。接下来我需要在订单表中插入新订单。
以下是客户表:
CID CNAME CITY DISCNT
c001 Tiptop Duluth 10
c002 Basics California 12
c003 7/11 California 8
c004 ACME Duluth 8
c006 ACME Kyoto 0
c007 Goldberg NYC 15
以下是订单表:
ORDNO MON CID AID PID QTY DOLLARS
1011 jan c001 a01 p01 1000 450
1012 jan c001 a01 p01 1000 450
1019 feb c001 a02 p02 400 180
1017 feb c001 a06 p03 95959 540
1018 feb c001 a03 p04 600 540
1023 mar c001 a04 p05 500 450
1022 mar c001 a05 p06 400 720
1025 apr c001 a05 p07 800 720
1013 jan c002 a03 p03 1000 880
1026 may c002 a05 p03 800 704
1015 jan c003 a03 p05 1200 1104
1014 jan c003 a03 p05 1200 1104
1021 feb c004 a06 p01 1000 460
1016 jan c006 a01 p01 1000 500
1020 feb c006 a03 p07 600 600
1024 mar c006 a06 p01 800 400
我创建的触发器是:
create or replace trigger UpdateDiscnt
after insert or update on orders
for each row
begin
update customers set discnt = 0.4 + :old.discnt where
customers.cid=:new.cid;
end;
/
答案 0 :(得分:0)
错误是oracle错误,订单表中没有discnt,因此任何版本的old.discnt都不正确。
尝试
create or replace trigger UpdateDiscnt
after insert or update on orders
for each row
begin
update customers set discnt = 0.4 + discnt
where customers.cid= :new.cid;
end;
/