在OrderDetail上定义一个触发器,如果购物者改变了定单的数量,玩具的成本也自动地改变。
(提示:Toy cost = Quantity * Toy Rate)
create trigger  update_OrderDetail
after update on OrderDetail
for each row
as begin
if(new.siQty!<>old.siQty)
then 
update OrderDetail
set new.mToyCost=siQty*(select mToyRate from Toys where Toys.cToyId=OrderDetail.cToyId);
end if;
end;
这样写哪里有错?请写个对的 谢谢啦 

解决方案 »

  1.   

    create trigger update_OrderDetail
    after update on OrderDetail
    for each row
    as begin
    if(:new.siQty<>:old.siQty)
    then  
    update OrderDetail
    set :new.mToyCost=:new.siQty*(select mToyRate from Toys where Toys.cToyId=:new.OrderDetail.cToyId);
    end if;
    end;
      

  2.   

    -- 给个例子给你参考吧!楼主好运!
    CREATE OR REPLACE TRIGGER IMSI2MOBILE_UserPoints_trig
    AFTER INSERT OR UPDATE OR DELETE ON imsi2mobile
    FOR EACH ROW
    DECLARE
      v_singlepoints NUMBER(18);
    BEGIN
      IF UPDATING THEN
        UPDATE UserPoints SET mobile=:new.mobile WHERE mobile=:old.mobile;
      ELSIF DELETING THEN
        DELETE FROM UserPoints WHERE mobile=:old.mobile;
      ELSIF INSERTING THEN
        SELECT singlepoints INTO v_singlepoints FROM opera_points_map WHERE useropera='TO_REGISTER';
        INSERT INTO UserPoints(mobile, usertype, points,grade, cdate) VALUES(:new.mobile,1,v_singlepoints,1,:new.cdate);
      END IF;
    END;
    /
      

  3.   

    create trigger update_OrderDetail
    after update on OrderDetail
    for each row
    as begin
    if(:new.siQty!<>:old.siQty)
    then  
       --思路是这样,但可能有语法错误(未经调试)
       :new.mToyCost := :new.siQty * (select mToyRate from Toys where Toys.cToyId = :new.cToyId);
    /*  update触发器,不能更新基表
    update OrderDetail
    set new.mToyCost=siQty*(select mToyRate from Toys where Toys.cToyId=OrderDetail.cToyId);
    */
    end if;
    end;
      

  4.   

    你这个触发器会导致ora-04091 错误:变异表。
      

  5.   


    create trigger update_OrderDetail
    after update on OrderDetail
    for each row
    as begin
    if(:new.siQty <>:old.siQty)  
    then  
    :new.mToyCost:=siQty*(select mToyRate from Toys where Toys.cToyId=:new.cToyId);
    end if;
    end;--!<> 不明白你是不不等于 还是不等于
    --基表(OrderDetail) 更新 不能用于update/insert, 只能是 :new.col:=某个值
      

  6.   

    将4楼的after update on OrderDetail
    改为before update of siQty on OrderDetail
      

  7.   

    你的参数不对啊。。
    :new
    :old
    上网看看 吧