1. Update/delete based on ROWID.
Rowid access is the most efficient access path in Oracle. Here is a nice post at ITPUB (in Chinese) demonstrating this concept with a live production example.
2. Bulk collection feature
Below is a simple code example for using ROWID based driver table and bulk collection:
declare
cursor c is
select rowid id from t where val=0 order by rowid;
counter number :=0;
rowids dbms_sql.urowid_table;
begin
open c;
loop
fetch c bulk collect into rowids limit 1000;
forall i in 1..rowids.count
update t set val=1
where rowid = rowids(i);
commit;
counter := counter + 1;
dbms_output.put_line('Updated batch ' counter );
exit when c%notfound;
end loop;
close c;
end;
/
1 comment:
To add exception handling code in the bulk collect, check Oracle documentation: Reducing Loop Overhead for DML Statements and Queries with Bulk SQL
Post a Comment