Thursday, 24 May 2012

Is it possible to assign a dynamic value to a loop counter? | PL SQL

Yes, it is possible to assign a dynamic value to the loop counter at the time of execution  as shown in the following code snippet 
select count(emp_code) into v_emp_count from t_employees
FOR counter IN 1.. v_emp_count LOOP
Statement....
END LOOP;

In the preceding code snippet, the employee count is derived from the table at run time and the counter is used to iterate the FOR-LOOP.