Q:

Oracle SQL: How to define loop counter value in a column?

(I am very new to SQL ...) I want to define a loop where the loop counter must be in a column (e.g. ID):
for i in (select ID from IDTable) loop 
...
Of course the above doesn't work. Any help?

A:

for i in (select ID from IDTable) loop ...
Of course the above doesn't work.

It does work, unless you are confused the value of loop counter and the id you are selecting in the for loop are same.
SQL> set serveroutput on
SQL> BEGIN
  2    FOR i IN
  3    (SELECT empno FROM emp
  4    )
  5    LOOP
  6      dbms_output.put_line(i.empno);
  7    END LOOP;
  8  END;
  9  /
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

PL/SQL procedure successfully completed.

SQL>

