if ... then goto ALable; endif; cursor2 end <<ALable>> ---这里可能需要null; cursor1 end; 就行了
偶喜欢用 for i in cursor1 loop; for j in cursor2 loop; Exit; --这里用Exit可以退出1层循环 end loop; end loop;
谢楼上的,我试过了,可是好象不行。我把我的部分代码贴出来吧! 请大家继续支持! 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;
好象我的goto语句没能生效啊,请大家帮忙查查原因,谢谢了!
exit好象不行,我一开始就是用exit的!
我很少用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 过程已成功完成。
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;
cusor1 begin cursor2 begin
if ... then
goto ALable;
endif; cursor2 end
<<ALable>>
---这里可能需要null;
cursor1 end;
就行了
for i in cursor1 loop;
for j in cursor2 loop; Exit; --这里用Exit可以退出1层循环
end loop;
end loop;
请大家继续支持!
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;
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 过程已成功完成。
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;