Friday, 11 March 2016

Bulk binds with error handling

  1. declare
  2. cursor curr_cur is select * from emp;
  3. type emp_tab is table of curr_cur%rowtype;
  4. emp_array emp_tab;
  5. errors number;
  6. dml_errors exception;
  7. pragma exception_init(dml_errors,-24381);
  8. begin
  9. open curr_cur;
  10. loop
  11. fetch curr_cur  bulk collect into emp_array limit 35;
  12. forall  i in emp_array.first..emp_array.last save exceptions
  13. insert into emp_temp3 values emp_array(i);
  14. exit when curr_cur%notfound;
  15. end loop;
  16. close curr_cur;
  17. exception
  18. when dml_errors then
  19. errors:=sql%bulk_exceptions.count;
  20. dbms_output.put_line('number of statements failed are '||errors);
  21. for i in 1..errors loop
  22. dbms_output.put_line('error #'||i|| ' is occured during '|| 'iterations #' ||sql%bulk_exceptions(i).error_index);
  23. dbms_output.put_line('error  message is ' || SQLERRM(-sql%bulk_exceptions(i).error_code));
  24. end loop;
  25. end;
  26. /

No comments:

Post a Comment

Query to find request set and its responsibility

  SELECT FA.application_name,        fr.responsibility_name program_attached_to,        frg.request_group_name,        fcp.request_set_name,...