I am trying to update records in bulk. After running for all update I need to call a procedure and send all successfully updated id's as one of the parameter to the procedure.All those id's for which update was not performed due to some error should not be passed to the procedure. My code is below.
DECLARE
type emp_type is TABLE OF number;
EMP_ID EMP_TYPE;
lv_select varchar2(4000):='select employee_id from EMPLOYEE where dept_NO=1';
BEGIN
EXECUTE IMMEDIATE lv_select BULK COLLECT INTO emp_id ;
FORALL INDX IN 1 ..emp_id.COUNT SAVE EXCEPTIONS
UPDATE emp Set salary=salary+1000
where employee_id=emp_id(INDX);
PROC (
PAR1=>'abc',
par2=>emp_id(INDX),
par3=>'xyz'
);
EXCEPTION
WHEN OTHERS
THEN
FOR J IN 1 .. SQL%BULK_EXCEPTIONS.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE(SQLERRM (-SQL%BULK_EXCEPTIONS (j).ERROR_CODE));
END LOOP;
END;
This can be simply achieved by using simple for LOOP. Hope below snoippet helps.