循环退出时机

open cur_view_name_detail;      --获得视图列表
    loop                        
      fetch cur_view_name_detail into lv_table_name;
      lv_detail_sql:=replace(lv_detail_sql_undo,'VW_OP_MAIL_01_1204',lv_table_name);
      lv_detail_sql:=replace(lv_detail_sql,'g_run_day_n',to_char(g_run_day_n));
     
     open cur_detail for lv_detail_sql ;--using(g_run_day_n);
。。。。。。
  commit;
         exit when cur_detail%notfound or cur_detail%notfound is null;             
         end loop;  
         close cur_detail; 
         oss_pkg_stat_public.oss_stat_step_log_info(1,g_package_proce_name ,4,'结束--比较省份:'||lv_table_name); 
             
   exit when cur_view_name_detail%notfound or cur_view_name_detail%notfound is null;             
   end loop;  
   close cur_view_name_detail;  
   oss_pkg_stat_public.oss_stat_step_log_info(1,g_package_proce_name ,5,'结束--比较行为31省份');                                   
   commit;
这是个双循环游标提取,而且是动态语句。
外面循环主要是获得物理表名,并且通过替换手法把动态语句的表名和时间参数给替换掉,形成真实的SQL语句。
第二个循环是执行动态语句并提取数据到临时表。
后面代码是退出条件。
发现 如果外循环只有一条记录,则内循环要执行两次。
后来经同事提醒,才感觉 这是个do...while 先执行后判断的循环

For l_Cur_Deal_Table In (Select Table_Type,                                     Rule_No,                                     Sub_Rule_No As Provcodde,                                     Table_Name                                From Source_Table_Dic_t                               Where Rule_No = Pi_Rule_No)

     Loop

...
end loop;
是先判断后执行 不用人工写判断条件。
 
为此、执行前追加一条判断语句。
open cur_view_name_detail;      --获得视图列表
    loop                        
      fetch cur_view_name_detail into lv_table_name;
      lv_detail_sql:=replace(lv_detail_sql_undo,'VW_OP_MAIL_01_1204',lv_table_name);
      lv_detail_sql:=replace(lv_detail_sql,'g_run_day_n',to_char(g_run_day_n));
      exit when cur_view_name_detail%notfound or cur_view_name_detail%notfound is null;     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值