触发器创建成功后,插入数据的时候就报错了..说触发器 不能读 表已经更改~~line 6
实在找不出错误 小弟菜鸟  希望兄弟们来看看
create or replace trigger change_piao
after insert on booking_20051738
for each row
declare
var_s hanban_20051738.tsum%type;
var_d  booking_20051738.tcount%type;
begin
select tsum into var_s from hanban_20051738 where hbanhao=:new.hbanhao;
select tcount into var_d from booking_20051738 where hbanhao=:new.hbanhao;
if var_s>=var_d then
update hanban_20051738
set tsum=tsum-var_d
where hanban_20051738.hbanhao=:new.hbanhao;
else
rollback;
end if;
end;

解决方案 »

  1.   

    你调试下,看看走到哪步报错
    select tsum into var_s from hanban_20051738 where hbanhao=:new.hbanhao; 
    select tcount into var_d from booking_20051738 where hbanhao=:new.hbanhao; 
    这也没有必要读2次
      

  2.   

    两个错误,行触发器中不允许再对需触发的表做DML操作,触发器中不能有commit/rollback。
    create or replace trigger change_piao 
    after insert on booking_20051738 
    for each row 
    declare 
    var_s hanban_20051738.tsum%type; 
    var_d  booking_20051738.tcount%type; 
    begin 
    select tsum into var_s from hanban_20051738 where hbanhao=:new.hbanhao; 
    --select tcount into var_d from booking_20051738 where hbanhao=:new.hbanhao; 
    --if var_s>=var_d then 
    if var_s>=:new.tcount then 
    update hanban_20051738 
    set tsum=tsum-:new.tcount 
    where hanban_20051738.hbanhao=:new.hbanhao; 
    else 
    --rollback; 
    raise_application_error(-20099,'数据错误');
    end if; 
    end; 
      

  3.   

    触发中不能有事务语句。就是你的rollback是不能在触发器中出现的。