Forall in indices of : forall « PL SQL Statements « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE employee (
  2     employee_id NUMBER,
  3     last_name VARCHAR2(30),
  4     first_name VARCHAR2(30),
  5     salary NUMBER
  6  );

Table created.

SQL> INSERT INTO employee (employee_id, last_name, first_name, salary)VALUES (1, 'G', 'J', 100000);

1 row created.

SQL>
SQL> INSERT INTO employee (employee_id, last_name, first_name, salary)VALUES (2, 'G', 'H', 100000);

1 row created.

SQL>
SQL> SELECT employee_id FROM employee  WHERE salary = 10000;

no rows selected

SQL>
SQL> DECLARE
  2     TYPE employee_aat IS TABLE OF employee.employee_id%TYPE INDEX BY PLS_INTEGER;
  3
  4     l_employees employee_aat;
  5
  6     TYPE boolean_aat IS TABLE OF BOOLEAN
  7        INDEX BY PLS_INTEGER;
  8
  9     l_employee_indices   boolean_aat;
 10  BEGIN
 11     l_employees (1) := 7839;
 12     l_employees (100) := 7654;
 13     l_employees (500) := 7950;
 14     --
 15     l_employee_indices (1) := TRUE;
 16     l_employee_indices (500) := TRUE;
 17     l_employee_indices (799) := TRUE;
 18     --
 19     FORALL l_index IN INDICES OF l_employee_indices
 20        BETWEEN 1 AND 500
 21        UPDATE employee
 22           SET salary = 10000
 23         WHERE employee_id = l_employees (l_index);
 24  END;
 25  /

PL/SQL procedure successfully completed.

SQL>
SQL> SELECT employee_id FROM employee  WHERE salary = 10000;

no rows selected

SQL>
SQL>
SQL> drop table employee;

Table dropped.

SQL>








22.18.forall
22.18.1.The FORALL command builds a set of SQL statements and executes all of them at once.
22.18.2.Use for all to insert value to table collection of rowtype
22.18.3.Use VALUES OF
22.18.4.Use VALUES OF with undefined row
22.18.5.Forall in indices of
22.18.6.Use forall to loop through first element to last element in a table collection of number