set serveroutput on
declare
v_bulk_errors EXCEPTION;
errorCount NUMBER;
errorCount1 NUMBER ;
CURSOR R_STATUS_DATA IS
SELECT SCH.SCH_key
--,mil.mil_name, usr.usr_key,usr.usr_login
FROM SCH , OSI osi, MIL, STA, TOS,PKG, usr,orc
WHERE SCH.SCH_KEY =OSI.SCH_KEY
AND OSI.MIL_KEY =MIL.MIL_KEY
AND SCH.SCH_STATUS =STA.STA_STATUS
AND PKG.PKG_KEY = OSI.PKG_KEY
AND MIL.TOS_KEY =TOS.TOS_KEY
AND PKG.PKG_KEY =TOS.PKG_KEY
and osi.orc_key=orc.orc_key
and orc.usr_key=usr.usr_key
AND PKG.PKG_TYPE = 'Provisioning'
AND STA.STA_BUCKET = 'Rejected'
AND TO_CHAR(SCH.SCH_CREATE, 'YYYYMMDD') <= '20160406'
AND MIL.MIL_NAME= '?' order by SCH.SCH_key;
TYPE R_statusArray IS TABLE OF R_STATUS_DATA%ROWTYPE;
v_R_statusObject R_statusArray;
begin
OPEN R_STATUS_DATA;
LOOP
FETCH R_STATUS_DATA BULK COLLECT INTO v_R_statusObject;
EXIT WHEN R_STATUS_DATA%NOTFOUND;
end loop;
CLOSE R_STATUS_DATA;
dbms_output.put_line(' Count -> '||v_R_statusObject.COUNT ) ;
FORALL i IN v_R_statusObject.FIRST..v_R_statusObject.LAST SAVE EXCEPTIONS
update sch set sch_status='C',sch_update=sysdate,sch_note='Manual Update from Staus R -> C' where sch_status='R'
and sch_key=v_R_statusObject(i).sch_key;
COMMIT;
dbms_output.put_line('Successful Completion' );
EXCEPTION WHEN v_bulk_errors THEN
errorCount := SQL%BULK_EXCEPTIONS.COUNT;
DBMS_OUTPUT.PUT_LINE('Number of UPDATE statements that failed : ' || errorCount);
ROLLBACK;
FOR i IN 1..errorCount LOOP
errorCount1:= SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
DBMS_OUTPUT.PUT_LINE('Error #' || i || ' Exception occurred during Updating Index #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX );
DBMS_OUTPUT.PUT_LINE('Error message is ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE) );
END LOOP;
end;
/
No comments:
Post a Comment