可能还没有表达清楚,如何使第二个SELECT语句触发异常后,在异常处理后,也能接着执行
第二个SELECT 语名后的其它语句直到存贮过程完全执行

解决方案 »

  1.   

    可以这么作,先select count(*) into v_i from .... where ....
    然后判断v_i是否等于1,如果是执行 select sum(a.sl2) into   temp_int2 from table_A a,table_b b where  (a.id=b.id);
    如:
    select count(*) into v_i from table_A a,table_b b where  (a.id=b.id); 
    if v_i=1 then
     select sum(a.sl1) into   temp_int1 from table_A a,table_b b where  (a.id=b.id);
    end if;
    select count(*) ...
    if v_i=1 then ...
    ...
      

  2.   

    select sum() will never threw a NO_DATA_FOUND exception !
      

  3.   

    create or replace procedure AAA
    as
      temp_int1  number(4);
      temp_int2  number(4);
    begin
     begin
      select sum(a.sl1) into   temp_int1 from table_A a,table_b b where  (a.id=b.id); 
      EXCEPTION
      WHEN NO_DATA_FOUND  THEN
        .......
     end;
     begin
      select sum(a.sl2) into   temp_int2 from table_A a,table_b b where  (a.id=b.id);
      EXCEPTION
       WHEN NO_DATA_FOUND  THEN
        .......
     end;
    end;
      

  4.   

    black_snail(●龙飞虎○) 说的没错啊。 
    聚组函数AVG或SUM用在select into里最多返回的
    temp_int1、temp_int2为空,不会产生例外的。
    如果贴主还有其他不用SUM的语句在执行,那么
    用qiuyang_wang(小数点) 的方式程序比较清晰。
      

  5.   

    此问题提得非常好,已测过,的确用聚组函数不会触发异常.
    那你就不要用此方法实现了。用以下:
    create or replace procedure AAA
    as
      temp_int1  number(4);
      temp_int2  number(4);
    begin
      select sum(a.sl1) into   temp_int1 from table_A a,table_b b where  (a.id=b.id); 
      if temp_int1 is null then
      ...
      end if;
      select sum(a.sl2) into   temp_int2 from table_A a,table_b b where  (a.id=b.id);
      if temp_int2 is null then
      ....
      end if;  
    ...
    end;
    /