Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1149786
  • 博文数量: 178
  • 博客积分: 2776
  • 博客等级: 少校
  • 技术积分: 2809
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-22 15:36
文章分类

全部博文(178)

文章存档

2014年(3)

2013年(66)

2012年(109)

分类: Oracle

2012-05-22 09:29:12

本文介绍Oracle procdure loop的循环异常的处理方法:

     for num in 1..total loop

        begin

         strsql := 'select ssid from (select temp.sp_id as ssid, rownum as ssnum
                from tempInfo temp) where ssnum='|| num;
         execute immediate strsql into tempspid;

         strsql := 'update tempInfo set black_count =
                (select count(black.id) as blackcount
                from nm_black_and_object black where black.sp_id =' || tempspid || ')
                where sp_id=' || tempspid;
         execute immediate strsql;

        
         table_name := 'NM_NET_USER_'||tempspid;

        dbms_output.put_line(table_name);

         strsql := 'update tempInfo set white_count =
                (select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
                where us.status in (1,2,3))
                where sp_id=' || tempspid;
         execute immediate strsql;--
此处可能引发 试图不存在异常 ,但是不该影响下面业务处理 

      end ;      
     end loop;

 

 

 

       --方法一 通过一次select 判断试图是否存在 ,如果存在则执行

         strsql := 'select count(*) from user_tables where table_name='''||table_name||'''';
         execute immediate strsql INTO counter ;

        

         IF counter > 0 THEN

               strsql := 'update tempInfo set white_count =
                (select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
                where us.status in (1,2,3))
                where sp_id=' || tempspid;更多Oracle文章请看http://www.cuug.com/
         execute immediate strsql;--
此处可能引发 试图不存在异常 ,但是不该影响下面业务处理     

        
         END IF ;

 

    ---方法2 通过EXCEPTION

          strsql := 'update tempInfo set white_count =
                (select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
                where us.status in (1,2,3))
                where sp_id=' || tempspid;
         execute immediate strsql;--
此处可能引发 试图不存在异常 ,但是不该影响下面的业务处理  

         exception

         when others then null ;  

关于Oracle procdure loop 循环报异常后如何继续下一次循环就介绍到这里,希望能给朋友们一些帮助或启迪。

阅读(8300) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~