zoukankan      html  css  js  c++  java
  • NC已付款客商不能删行(银行账户),没付款客商同步删行trigger|2in1 if else|

    if.. then.. else用法

    create or replace trigger DELETE_CUSTBANK
    
      before delete on bd_custbank
    
      for each row
    
    declare
    
      -- local variables here
    
      pk_bas char(20);
    
      cursor basjob(id char) is
      
        select pk_custbank
        
          from ncv5.bd_custbank /*目标数据库表*/
        
         where pk_custbank = id
              
           and nvl(dr, 0) = 0
           and pk_custbank not in
               (select bd_custbank.pk_custbank
                  from ncv5.arap_djfb, ncv5.bd_accbank, ncv5.bd_custbank
                 where bd_accbank.pk_accbank = arap_djfb.skyhzh
                   and bd_accbank.pk_accbank = bd_custbank.pk_accbank);
    
    begin
    
      /*判断数据是否在目标数据库存在*/
    
      open basjob(:old.pk_custbank);
    
      loop
      
        fetch basjob
        
          into pk_bas;
        /*dbms_output.put_line('pa_bas:'||pk_bas);*/
        exit when basjob%notfound;
      
      end loop;
    
      close basjob;
    
      /******************************/
    
      if pk_bas is not null then
      
        begin
        
          delete ncv5.bd_custbank /*目标数据库表*/
          
           where pk_custbank = :old.pk_custbank;
        
        end;
      else
        raise_application_error(-20001,
                                :old.account || '已从网银付款,不能修改或删行,请取消!');
      
      end if;
    end DELETE_CUSTBANK;
    重要声明:cursor中是not in 这里的是“否”,然后 if pk_bas is not null then
    不能理解为“否”而需要理解“数值存在”,这样就是找到非付款客商了,then可以同步删除,否则报错
  • 相关阅读:
    HDU 3081 Marriage Match II
    HDU 4292 Food
    HDU 4322 Candy
    HDU 4183 Pahom on Water
    POJ 1966 Cable TV Network
    HDU 3605 Escape
    HDU 3338 Kakuro Extension
    HDU 3572 Task Schedule
    HDU 3998 Sequence
    Burning Midnight Oil
  • 原文地址:https://www.cnblogs.com/sumsen/p/2554659.html
Copyright © 2011-2022 走看看