Wednesday, August 24, 2011

Bulk Collect Example

Declare
  Type emprec IS RECORD(
    empno Number,
    name  varchar2(40));
  TYPE emptab IS TABLE OF emprec;
  cursor empcur IS
    select * from emp1;
  emptable emptab;

BEGIN
  OPEN empcur;
  FETCH empcur BULK COLLECT
    INTO emptable;

  if (nvl(emptable.LAST 0) > 0) then
    FOR i in emptable.FIRST .. emptable.LAST LOOP
      BEGIN
           INSERT INTO EMP1(empno,name) values (emptable(i).empno,emptable(i).name);
      END;
    END LOOP;
  END IF;

  COMMIT;
 END;

No comments: