`
coolerbaosi
  • 浏览: 730894 次
文章分类
社区版块
存档分类
最新评论

Oracle/PLSQL: FOR Loop 循环语句

 
阅读更多

Oracle/PLSQL: FOR Loop:
http://www.techonthenet.com/oracle/loops/for_loop.php

Loops with PL/SQL:
http://www.adp-gmbh.ch/ora/plsql/loops.html


The syntax for the FOR Loop is:

Sql代码 收藏代码
  1. FORloop_counterIN[REVERSE]lowest_number..highest_number
  2. LOOP
  3. {.statements.}
  4. ENDLOOP;


You would use a FOR Loop when you want to execute the loop body a fixed number of times.




Let's take a look at an example.



Sql代码 收藏代码
  1. FORLcntrIN1..20
  2. LOOP
  3. LCalc:=Lcntr*31;
  4. ENDLOOP;


This example will loop 20 times. The counter will start at 1 and end at 20.




The FOR Loop can also loop in reverse. For example:



Sql代码 收藏代码
  1. FORLcntrINREVERSE1..15
  2. LOOP
  3. LCalc:=Lcntr*31;
  4. ENDLOOP;


This example will loop 15 times. The counter will start at 15 and end at 1. (loops backwards)





oracle学习--循环语句:


http://www.cnblogs.com/happyday56/archive/2007/06/22/793102.html


On Cursor FOR Loops:


http://www.oracle.com/technology/oramag/oracle/08-nov/o68plsql.html




A Example:


Sql代码 收藏代码
  1. CREATEORREPLACE
  2. procedureTEST_p(eq_idvarchar,eq_id_newvarchar,etp_nonumber)is
  3. v_eq_idvarchar2(20):=eq_id;
  4. v_eq_id_newvarchar2(20):=eq_id_new;
  5. v_etp_nonumber:=etp_no;
  6. begin
  7. forvRowsin(selectAQD_SEQ_MD_ET_PROCEDURES.nextvalasid,certify_yn,required_yn,tpr_nofromAQD_MD_ET_PROCEDURESwhererownum<5)
  8. LOOP
  9. dbms_output.put_line(vRows.id);
  10. insertintotest(id,col2,col3,col4)values(vRows.id,vRows.certify_yn,vRows.required_yn,vRows.tpr_no);
  11. ENDLOOP;
  12. endTEST_p;
  13. createtableTEst(
  14. idnumber(38),
  15. col2varchar2(1),
  16. col3varchar2(1),
  17. col4number(38)
  18. )

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics