Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Bulk Operation That Continues Despite Exceptions

DROP TABLE emp_temp CASCADE CONSTRAINTS PURGE;

-- create a temporary table for this example

CREATE
TABLE emp_temp
AS
SELECT *
FROM employees;



DECLARE

TYPE empid_tab IS TABLE OF employees.employee_id%TYPE;
emp_sr EMPID_TAB;
-- create an exception handler for ORA-24381
errors NUMBER;
dml_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(dml_errors,-24381);
BEGIN
SELECT employee_id
BULK COLLECT INTO emp_sr
FROM emp_temp
WHERE hire_date < '30-DEC-94';
-- add '_SR' to the job_id of the most senior employees
FORALL i IN emp_sr.FIRST..emp_sr.LAST SAVE EXCEPTIONS
UPDATE emp_temp
SET job_id = job_id
||'_SR'
WHERE Emp_sr(i) = emp_temp.employee_id;
-- If any errors occurred during the FORALL SAVE EXCEPTIONS,
-- a single exception is raised when the statement completes.
EXCEPTION
WHEN dml_errors THEN -- Now we figure out what failed and why.

errors := SQL%BULK_EXCEPTIONS.COUNT;
dbms_output.Put_line('Number of statements that failed: '
||errors);
FOR i IN 1.. errors LOOP
dbms_output.Put_line('Error #'
||i
||' occurred during '
||'iteration #'
||SQL%Bulk_exceptions(i).ERROR_INDEX);
dbms_output.Put_line('Error message is '
||Sqlerrm(-SQL%Bulk_exceptions(i).ERROR_CODE));
END LOOP;
END;
/



OUTPUT:-

Number of statements that failed: 2
Error #1 occurred during iteration #5
Error message is ORA-12899: value too large for column (actual: , maximum: )
Error #2 occurred during iteration #12
Error message is ORA-12899: value too large for column (actual: , maximum: )

PL/SQL procedure successfully completed.

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-