Thursday, October 4, 2012

In-Binding - Bulk Binding in Native Dynamic SQL

The same progression (explicit row by row processing, bulk binding, bulk binding in native dynamic SQL) is supported for DML (insert, update and delete) thus…
declare
  type employee_ids_t is table of employees.employee_id%type
    index by binary_integer;
  employee_ids employee_ids_t;
begin
  employee_ids(1) := 151;
  employee_ids(2) := 162;
  employee_ids(3) := 173;
 
 
  for j in employee_ids.first..employee_ids.last
  loop
    update employees set salary = salary*1.1
      where employee_id = employee_ids(j);
  end loop;
end;
…then…
forall j in employee_ids.first..employee_ids.last
  update employees set salary = salary*1.1
    where employee_id = employee_ids(j);
…then…
forall j in employee_ids.first..employee_ids.last
  execute immediate 'update employees set salary = salary*1.1'
  || ' where employee_id = :the_id'
 
   using employee_ids(j) /* new at 9i */;