Oracle PL/SQL - Specifying FOR LOOP Statement Bounds at Run Time

Description

Specifying FOR LOOP Statement Bounds at Run Time

Demo

SQL>
SQL> CREATE TABLE temp (
  2    emp_no      NUMBER,
  3    email_addr  VARCHAR2(50)-- www  .ja  v  a 2  s  .  co m
  4  );
SQL>
SQL> DECLARE
  2    emp_count  NUMBER;
  3  BEGIN
  4    SELECT COUNT(empid) INTO emp_count
  5    FROM emp;
  6
  7    FOR i IN 1..emp_count LOOP
  8      INSERT INTO temp (emp_no, email_addr)
  9      VALUES(i, 'to be added later');
 10    END LOOP;
 11  END;
 12  /

PL/SQL procedure successfully completed.

SQL>

Related Topic