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:
- FOR loop_counter IN [REVERSE] lowest_number..highest_number
- LOOP
- {.statements.}
- END LOOP;
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.
- FOR Lcntr IN 1..20
- LOOP
- LCalc := Lcntr * 31;
- END LOOP;
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:
- FOR Lcntr IN REVERSE 1..15
- LOOP
- LCalc := Lcntr * 31;
- END LOOP;
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:
- CREATE OR REPLACE
- procedure TEST_p(eq_id varchar,eq_id_new varchar,etp_no number) is
- v_eq_id varchar2(20) :=eq_id;
- v_eq_id_new varchar2(20) := eq_id_new;
- v_etp_no number:=etp_no;
- begin
- for vRows in (select AQD_SEQ_MD_ET_PROCEDURES.nextval as id,certify_yn,required_yn,tpr_no from AQD_MD_ET_PROCEDURES where rownum <5)
- LOOP
- dbms_output.put_line(vRows.id);
- insert into test(id,col2,col3,col4) values(vRows.id,vRows.certify_yn,vRows.required_yn,vRows.tpr_no);
- END LOOP;
- end TEST_p;
- create table TEst(
- id number(38),
- col2 varchar2(1),
- col3 varchar2(1),
- col4 number(38)
- )