存储过程

create or replace procedure B_SHINCHOKU_S3
is

cursor cur_SHINCHOKU3 is
select T1.pref_code as pref_code ,T1.soshikicode as soshikicode,T1.A as kakunin_end_count,T2.B as kakunin_count,round(T2.B/T1.A*100,1) as kakunin_radio
from (select pref_code,soshikicode,count(LND_T_HOUJINNEW.ID) A  from LND_T_HOUJINNEW where LND_T_HOUJINNEW.conferm_flg = 1 group by pref_code,soshikicode) T1,
     (select pref_code,soshikicode,count(LND_T_HOUJINNEW.ID) B from LND_T_HOUJINNEW where LND_T_Houjinnew.checkedflg = 1 group by pref_code,soshikicode) T2    
where
 T1.pref_code = T2.pref_code and
 T1.soshikicode = T2.soshikicode; 

  O_GK_RTN_CODE varchar2(100);
  houjinkaku_code varchar2(100);
   pref_code varchar2(100);
   ncount NUMBER(10);
begin

 FOR cur_result in cur_SHINCHOKU3 LOOP

   BEGIN
       houjinkaku_code := cur_result.soshikicode;
        pref_code := cur_result.pref_code;
       select Count(*) into ncount 
       From LND_T_Sinchoku_S
       where LND_T_Sinchoku_S.Country_Code = pref_code and LND_T_Sinchoku_S.houjinkaku_code = houjinkaku_code;
        if (ncount > 0 ) then
              update LND_T_Sinchoku_S
       set kakunin_end_count = cur_result.kakunin_end_count,kakunin_count = cur_result.kakunin_count,kakunin_radio = cur_result.kakunin_radio,insert_date = SYSDATE, update_date = SYSDATE; 
 
 else
 
 insert into LND_T_Sinchoku_S(country_code,houjinkaku_code,kakunin_radio,kakunin_end_count,kakunin_count,insert_date,update_date)
 values(cur_result.pref_code,cur_result.soshikicode,cur_result.kakunin_radio,cur_result.kakunin_end_count,
        cur_result.kakunin_count,SYSDATE,SYSDATE);
  
        end if;
  end;

 END LOOP;
 --end;
 COMMIT;
--EXCEPTION
-- WHEN OTHERS THEN
 -- ROLLBACK;
 -- O_GK_RTN_CODE := sqlerrm;

end;
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值