行级触发器对当前表操作,”ORA-04091: 表 COMPANY 发生了变化, 触发器/函数不能读它“,解决方法...

 

行级触发器对当前表操作,”ORA-04091: 表 COMPANY 发生了变化, 触发器/函数不能读它“,解决方法:

1、自动产生另外一个独立的TRANSACTION,一般需要在其中写commit,见红色内容

 

create or replace trigger odpaydetailTrigger
  before insert or update on order_pay_detail  
  for each row
declare
  PRAGMA AUTONOMOUS_TRANSACTION;--自动产生另外一个独立的TRANSACTION,一般需要在其中写commit
  -- local variables here 一个订单 pay_reason=‘MAIN’只能有一个
  detailcount int;
  
begin
  if :new.pay_reason='MAIN' then 
     begin
          if inserting then
                begin
                        select count(1) into detailcount from order_pay_detail opd where opd.order_package_id=:new.order_package_id and opd.pay_reason='MAIN' AND PAY_SUC='Y';
                        if detailcount>=1 then
                           begin
                                 raise_application_error(-20020, '重复插入类型为MAIN的支付明细');
                           end;
                        end if;
                 end;
           end if;
           if updating then
                begin
                        --select count(*) into detailcount from order_pay_detail opd where opd.order_package_id=:new.order_package_id and opd.pay_reason='MAIN';
                        if (:new.pay_reason<>:old.pay_reason or :new.PAY_SUC<>:old.PAY_SUC) and :new.pay_reason='MAIN' and :new.PAY_SUC='Y' then
                           begin
                                select count(1) into detailcount from order_pay_detail opd where opd.order_package_id=:new.order_package_id and opd.pay_reason='MAIN' AND PAY_SUC='Y';
                                if detailcount >=1 then
                                    begin
                                    raise_application_error(-20020, '重复插入类型为MAIN的支付明细');
                                    end;
                                end if; 
                            end;
                        end if;
                 end;
           end if;
     end;
  end if;  
  COMMIT;
end odpaydetailTrigger;
 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值