呵呵,我碰到这样的问题,一般都是用过滤的方法的了,让他空转,转到最后一条就是了,不进行退出游标的了,好象在存储过程中没有BREAK这样的语句吧

解决方案 »

  1.   

    goto直接跳转到一个标号:
    cusor1 begin cursor2 begin
      
       if ... then
         goto ALable;
       endif; cursor2 end
    <<ALable>>
    ---这里可能需要null;
    cursor1 end;
    就行了
      

  2.   

    偶喜欢用
      for i in cursor1 loop;
        for j in cursor2 loop;      Exit;       --这里用Exit可以退出1层循环
        end loop;
      end loop;
      

  3.   

    谢楼上的,我试过了,可是好象不行。我把我的部分代码贴出来吧!
    请大家继续支持!
           while CarNum > 0 loop
              open Driver_Cur;
              loop
                fetch Driver_Cur
                  into Driver_No;
                RecNo := RecNo +1;                                  
                exit when Driver_Cur%notfound;
                select bBalance, dcBalance into IsBalance, BalanceMile from BISet;
                if IsBalance = 1 then
                  begin
                    select dcBalance, cFleetNo  into DriverMile, FleetNo from BIDriver
                     where vcDriverNo = Driver_No;
                    if BalanceMile > DriverMile then
                      begin
                        insert into rgOrderDetail
                          (Vcorderno,iDetailNo,Cfleetno, Vcdriverno)
                        values
                          (:new.vcOrderNo,RecNo,FleetNo, Driver_No);
                         goto ALable;                     
                      end;
                    end if;
                  end;
                else
                  begin
                    insert into rgOrderDetail
                      (Vcorderno, iDetailNo,Cfleetno, Vcdriverno)
                    values
                      (:new.vcOrderNo,RecNo,FleetNo, Driver_No);
                     goto ALable;
                  end;
                end if;
              end loop;
              <<ALable>>                                          
              close Driver_Cur;
              CarNum := CarNum - 1;
            end loop;
      

  4.   

    好象我的goto语句没能生效啊,请大家帮忙查查原因,谢谢了!
      

  5.   

    exit好象不行,我一开始就是用exit的!
      

  6.   

    我很少用Open ...fetch ... close;不太清楚但我知道用for循环时是可以的看看这个:
    SQL> begin
      2    for i in 1..9 loop
      3      for j in 1..9 loop
      4        dbms_output.put(to_char(i)||'*'||to_char(j)||'='||to_char(i*j)||'  ');
      5        if i=j then
      6          exit;
      7        end if;
      8      end loop;
      9      dbms_output.put_Line('');
     10    end loop;
     11  end;
     12  /
    1*1=1
    2*1=2  2*2=4
    3*1=3  3*2=6  3*3=9
    4*1=4  4*2=8  4*3=12  4*4=16
    5*1=5  5*2=10  5*3=15  5*4=20  5*5=25
    6*1=6  6*2=12  6*3=18  6*4=24  6*5=30  6*6=36
    7*1=7  7*2=14  7*3=21  7*4=28  7*5=35  7*6=42  7*7=49
    8*1=8  8*2=16  8*3=24  8*4=32  8*5=40  8*6=48  8*7=56  8*8=64
    9*1=9  9*2=18  9*3=27  9*4=36  9*5=45  9*6=54  9*7=63  9*8=72  9*9=81PL/SQL 过程已成功完成。
      

  7.   

    while CarNum > 0 loop
              open Driver_Cur;
              loop
                fetch Driver_Cur
                  into Driver_No;
                RecNo := RecNo +1;                                  
                exit when Driver_Cur%notfound;
                select bBalance, dcBalance into IsBalance, BalanceMile from BISet;
                if IsBalance = 1 then
                  begin
                    select dcBalance, cFleetNo  into DriverMile, FleetNo from BIDriver
                     where vcDriverNo = Driver_No;
                    if BalanceMile > DriverMile then
                      begin
                        insert into rgOrderDetail
                          (Vcorderno,iDetailNo,Cfleetno, Vcdriverno)
                        values
                          (:new.vcOrderNo,RecNo,FleetNo, Driver_No);
                         goto ALable;                     
                      end;
                    end if;             //我怀疑你的程序是否走到这里了,这里没有相应的提前结束语句              end;
                else
                  begin
                    insert into rgOrderDetail
                      (Vcorderno, iDetailNo,Cfleetno, Vcdriverno)
                    values
                      (:new.vcOrderNo,RecNo,FleetNo, Driver_No);
                     goto ALable;
                  end;
                end if;
              end loop;
              <<ALable>>                                          
              close Driver_Cur;
              CarNum := CarNum - 1;
            end loop;
      

  8.   

    呵呵,谢谢各位,问题解决了,是我自己粗心大意,写错变量了,其实exit和goto语句都可以,我都测试通过了!