SQL 语句while循环模版:
declare
i number(10) :=0;
begin
while i<1000 loop
insert into stu_liyy1 values(i,'lyy');
i :=i+1;
end loop;
commit;
exception
when others then
rollback;
end;
例子:
declare a int:=1;
begin
while a<=30 loop
update HSM_HSE_STCK_VRBL_ATTR v set v.HSE_STCK_RSRV_CODE=
(select reserved_code from (
select rownum i,stock_key, reserved_code from (
select w.MAIN_STCK_KEY stock_key,w.TNCY_ACQ_WAY_CODE reserved_code
from WRK_TNCY w where w.TNCY_STS_CODE = 'W'
union
select a.STCK_KEY stock_key,w.TNCY_ACQ_WAY_CODE reserved_code
from WRK_TNCY w,WRK_TNCY_ADTN_UNIT a
where w.TNCY_KEY=a.TNCY_KEY
and w.TNCY_STS_CODE = 'W'
))where i = a) where v.HSE_STCK_KEY =
(select stock_key from (
select rownum i,stock_key, reserved_code from (
select w.MAIN_STCK_KEY stock_key,w.TNCY_ACQ_WAY_CODE reserved_code
from WRK_TNCY w where w.TNCY_STS_CODE = 'W'
union
select a.STCK_KEY stock_key,w.TNCY_ACQ_WAY_CODE reserved_code
from WRK_TNCY w,WRK_TNCY_ADTN_UNIT a
where w.TNCY_KEY=a.TNCY_KEY
and w.TNCY_STS_CODE = 'W'
))where i = a);
a:=a+1;
end loop;
end;