views:

102

answers:

2

hi everyone, in plsql, i saw some one use for loop without define the loop index, and the database can execute correctly. but i can't find the description of this syntax in oracle documentation. can anyone explain it? great thanks!

the following code is an example, notice the *inner_c* is not defined:

declare
    v_current_nr NUMBER;
begin
    v_current_nr:=0;

    loop
     for inner_c in 1..4
     loop
      DBMS_OUTPUT.put_line(v_current_nr);
     end loop;

     v_current_nr:=v_current_nr+5;
     exit when v_current_nr>25;
    end loop;
end;
+3  A: 

inner_c is being used as the handle/variable for the loop. If you DBMS_OUTPUTed it, you'd see that it looped through the numbers 1 - 4 in this case.

It's implicitly declared as part of the loop mechanism. It will fall out of scope when the loop is over.

cagcowboy
A: 

What exactly do you mean "the loop index"?

You can have: For i in 1..5 which gives i the values of 1 through 5

But you can also have:

For record in myCursor Loop
  record.myField
End Loop

Which will return each time a row of the cursor. Maybe you can give an example of what you saw?

http://www.techonthenet.com/oracle/loops/for_loop.php

Littlefool