create or replace procedure pr_zhaozhenlong_loop /* 名稱:在存儲過程中執行3種循環語句 功能:利用循環給表中插入數據 調用: begin -- Call the procedure pr_zhaozhenlong_strsql; end; 創建人:趙振龍 創建時間:2007-01-03 */ is i int; begin i :=1; loop insert into tb_zhaozhenlong(rpt_date ,dept_id,item,qty) values(to_date('2007-01-01','yyyy-MM-dd'),'D'||i,'I'||i,round(i*100/3,3)); exit when i =10; i :=i+1; end loop; -- i :=1; while i<=5 loop insert into tb_zhaozhenlong(rpt_date ,dept_id,item,qty) values(to_date('2007-01-02','yyyy-MM-dd'),'D'||i,'I'||i,round(i*200/3,3)); i :=i+1; end loop; --如果指定了reverse選項,則循環控制變量會自動減1,否則自動加1 for j in reverse 1..10 loop --insert into tb_zhaozhenlong(rpt_date ,dept_id,item,qty) values(to_date('2007-01-03','yyyy-MM-dd'),'D'||j,'I'||j,round(j*300/3,3)); insert all --first,不會被重復插入 when i <> 2 then into tb_zhaozhenlong(rpt_date ,dept_id,item,qty) else into tb_temp_zhaozhenlong(rpt_date ,dept_id,item,qty)--如果兩個表結構完全一樣,則列舉不用列名 select to_date('2007-01-02','yyyy-MM-dd')as rpt_date,'D'||j as dept_id,'I'||j as item,round(j*300/3,3) as qty from dual; end loop; commit; --??????? <<outer_zzl>>--?????? for x in 1..10 loop <<inner_zzl>> for y in 1..100 loop i :=x*y; exit outer_zzl when i=500; exit when i =300; end loop inner_zzl; --<<inner_zzl>> end loop outer_zzl; --<<outer_zzl>> end; /