SAVE EXCEPTION CLAUSE

I'm trying to use the SAVE EXCEPTION clause and load all the records that error into an error table. example of my code is below. This code does not compile, it does not like the way I refrence a column in the collection ie.
recs.sku(SQL%BULK_EXCEPTIONS(i).ERROR_INDEX)
is there a better way to do this?
this is the code:
TYPE table_object IS TABLE OF tran_data_stage%ROWTYPE;
recs TABLE_OBJECT;
l_errors NUMBER(9);
CURSOR c_tdh_source IS
SELECT
sku,
store,
wh,
vdate,
NULL
FROM tran_data_history
WHERE vdate between sysdate -6
and sysdate;
BEGIN
OPEN c_tdh_source;
LOOP
BEGIN
FETCH c_tdh_source BULK COLLECT INTO recs LIMIT 100;
FORALL i IN recs.FIRST..recs.LAST SAVE EXCEPTIONS
INSERT INTO tran_data_stage VALUES recs(i);
EXIT WHEN c_tdh_source%NOTFOUND;
EXCEPTION
WHEN OTHERS THEN
l_errors := SQL%BULK_EXCEPTIONS.COUNT;
dbms_output.put_line('Number of errors is ' || l_errors);
FOR i IN 1..l_errors LOOP
dbms_output.put_line('Error ' || i || ' occurred during '||
'iteration ' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
dbms_output.put_line('Oracle error is ' ||
SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
INSERT INTO tran_data_stage_errors VALUES
recs.sku(SQL%BULK_EXCEPTIONS(i).ERROR_INDEX), --here is the error
5,
sysdate
END LOOP;
END;
END LOOP;
COMMIT;
CLOSE c_tdh_source;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('others error occured' || SQLERRM);
END;

Shouldn't that berecs(SQL%BULK_EXCEPTIONS(i).ERROR_INDEX).sku

Similar Messages

  • Save Exceptions Memory Issue

    I'm currently using a bulk collect (limit = 100) and a forall insert to load roughly 6.2 million records into a table. If I leave the "Save Exceptions" clause out of the procedure, all 6.2 million records are loaded without an error. THe amount of memory used never exceeds 40MB. If I include the "Save Exceptions" clause and put in the code to record any errors encountered, the memory jumps to over 200MB and the procedure is exceedingly slow. Also, I put a debugging statement after each forall insert to validate that the SQL%BULK_EXCEPTIONS.COUNT = 0 for each iteration. The procedure still completes with no errors, but the memory utilized is still way too high.
    Has anyone run into this before? Is there an environmental setting that needs to be set to use "Save Exceptions" with many rows of data?
    We are currently running 9.2.0.3.0.
    Thanks,
    Scott

    Hello.
    Thank you for your answers. Let me react:
    re 1. - this is the last possible solution which I don't want to take unless it is clear that the upgrade will fix the problem
    re 2. APPEND - just trying to improve the insert, I am not sure if this bit works, however it does not affect the memory problem
    re 3. in accordance with my understanding the LIMIT clause will not help. The amount of data we process in one step is not huge - not more then 10 000 records.
    re 4. we are already doing it, I was just interested whether someone has already seen this problem or not.
    So far I have not found any solutions...

  • How to handle multiple save exceptions (Bulk Collect)

    Hi
    How to handle Multiple Save exceptions? Is it possible to rollback to first deletion(of child table) took place in the procedure.
    There are 3 tables
    txn_header_interface(Grand Parent)
    orders(parent)
    order_items (Child)
    One transaction can have one or multiple orders in it.
    and one orders can have one or multiple order_items in it.
    We need to delete the data from child table first then its parent and then from the grand parent table.if some error occurs anywhere I need to rollback to child record deletion. Since there is flag in child table which tells us when to delete data from database.
    Is it possible to give name to Save exceptions?
    e.g.
    FORALL i IN ABC.FIRST..ABC.LAST SAVE EXCEPTIONS A
    FORALL i IN abc.FIRST..ABC.LAST SAVE EXCEPTIONS B
    if some error occurs then
    ROLLBACK A; OR ROLLBACK B;
    Please find the procedure attached
    How to handle the errors with Save exception and rollback upto child table deletion.
    CREATE OR REPLACE
    PROCEDURE DELETE_CONFIRMED_DATA IS
    TYPE TXN_HDR_INFC_ID IS TABLE OF TXN_HEADER_INTERFACE.ID%TYPE;
    TXN_HDR_INFC_ID_ARRAY TXN_HDR_INFC_ID;
    ERROR_COUNT NUMBER;
    BULK_ERRORS EXCEPTION;
    PRAGMA exception_init(bulk_errors, -24381);
    BEGIN
    SELECT THI.ID BULK COLLECT
    INTO TXN_HDR_INFC_ID_ARRAY
    FROM TXN_HEADER_INTERFACE THI,ORDERS OS,ORDER_ITEMS OI
    WHERE THI.ID = OS.TXN_HDR_INFC_ID
    AND OS.ID = OI.ORDERS_ID
    AND OI.POSTING_ITEM_ID = VPI.ID
    OI.DW_STATUS_FLAG =4 --data is moved to Datawarehouse
    MINUS
    (SELECT THI.ID FROM TXN_HEADER_INTERFACE THI,ORDERS OS,ORDER_ITEMS OI
    WHERE THI.ID = OS.TXN_HDR_INFC_ID
    AND OS.ID = OI.ORDERS_ID
    OI.DW_STATUS_FLAG !=4);
    IF SQL%NOTFOUND
    THEN
    EXIT;
    END IF;
    FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
    EXCEPTIONS
    DELETE FROM ORDER_ITEMS OI
    WHERE OI.ID IN (SELECT OI.ID FROM ORDER_ITEMS OI,ORDERS
    OS,TXN_HEADER_INTERFACE THI
    WHERE OS.ID = OI.ORDERS_ID
    AND OS.TXN_HDR_INFC_ID = THI.ID
    AND THI.ID = TXN_HDR_INFC_ID_ARRAY(i));
    FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
    EXCEPTIONS
    DELETE FROM ORDERS OS
    WHERE OS.ID IN (SELECT OS.ID FROM ORDERS OS,TXN_HEADER_INTERFACE THI
    WHERE OS.TXN_HDR_INFC_ID = THI.ID
    AND THI.ID = TXN_HDR_INFC_ID_ARRAY(i));
    FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
    EXCEPTIONS
    DELETE FROM TXN_HEADER_INTERFACE THI
    WHERE THI.ID = TXN_HDR_INFC_ID_ARRAY(i);
    COMMIT;
    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE, 'DD-MON-YY HH:MIPM')||':
    DELETE_CONFIRMED_DATA: INFO:DELETION SUCCESSFUL');
    EXCEPTION
    WHEN OTHERS THEN
    ERROR_COUNT := SQL%BULK_EXCEPTIONS.COUNT;
    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE, 'DD-MON-YY HH:MIPM')||':
    DELETE_CONFIRMED_DATA: ERROR:Number of errors is ' ||ERROR_COUNT);
    FOR indx IN 1..ERROR_COUNT LOOP
    DBMS_OUTPUT.PUT_LINE('Error ' || indx || 'occurred during
    '||'iteration'||SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX);
    DBMS_OUTPUT.PUT_LINE('Error is '
    ||SQLERRM(-SQL%BULK_EXCEPTIONS(indx).ERROR_CODE));
    END LOOP;
    END DELETE_CONFIRMED_DATA;
    Any suggestion would be of great help.
    Thanks in advance
    Anu

    If you have one or two places in your code that need multiple exceptions, just do it with multiple catch statements. Unless you are trying to write the most compact Programming 101 homework program, inventing tricks to remove two lines of code is not good use of your time.
    If you have multiple catches all over your code it could be a code smell. You may have too much stuff happening inside one try statement. It becomes hard to know what method call throws one of those exceptions, and you end up handling an exception from some else piece of code than what you intended. E.g. you mention NumberFormatException -- only process one user input inside that try/catch so it is easy to see what error message is given if that particular input is gunk. The next step of processing goes inside its own try/catch.
    In my case, the ArrayIndexOutOfBoundsException and
    NumberFormatException should be handled by the same way.Why?
    I don't think I have ever seen an ArrayIndexOutOfBoundsException that didn't indicate a bug in the code. Instead of an AIOOBE perhaps there should be an if statement somewhere that prevents it, or the algorithm logic should prevent it automatically.

  • SAVE EXCEPTIONS when fetching from cursors by BULK COLLECT possible?

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    Hello,
    I'm using an Cursor's FETCH by BULK COLLECT INTO mydata...
    Is it possible to SAVE EXCEPTIONS like with FORALL? Or is there any other possibility to handle exceptions during bulk-fetches?
    Regards,
    Martin

    The cursor's SELECT-statement uses TO_DATE(juldat,'J')-function (for converting an julian date value to DATE), but some rows contain an invalid juldat-value (leading to ORA-01854).
    I want to handle this "rows' exceptions" like in FORALL.
    But it could also be any other (non-Oracle/self-made) function within "any" BULK instruction raising (un)wanted exceptions... how can I handle these ones?
    Martin

  • Save Exceptions Limitation

    Hello Gurus,
    I have a problem with the Save Exceptions. I am using database 11g.
    When I am doing bulk insert I would like to insert the error records into a new table. But when I am inserting
    the error records I am getting the error "error:- ORA-00984: column not allowed here
    ORA-24381: error(s) in array DML".
    I am putting my code below.
    DECLARE
    CURSOR C_FRT2STORE IS
    SELECT ROWID,
    STORE_CD,
    MNR_CD,
    'FRT',
    DT,
    TO_DATE('31-DEC-2049'),
    FRT_FAC,
    TRUNC(SYSDATE),
    'ADMINUSR'
    FROM FRT2STORE;
    CURSOR C_FRT2STORE_EXC_TAB IS
    SELECT 'Y'
    FROM ALL_TABLES
    WHERE TABLE_NAME = 'FRT2STORE_EXC';
    TYPE STORE$MNR2CST_REC_TYPE IS RECORD
    (C_STORE$MNR2CST_ROWID VARCHAR2(100),
    C_STORE_CD STORE$MNR2CST.STORE_CD%TYPE,
    C_MNR_CD STORE$MNR2CST.MNR_CD%TYPE,
    C_CST_CD STORE$MNR2CST.CST_CD%TYPE,
    C_BEG_DT STORE$MNR2CST.BEG_DT%TYPE,
    C_END_DT STORE$MNR2CST.END_DT%TYPE,
    C_FAC NUMBER(13,3), --STORE$MNR2CST.FAC%TYPE,       
    C_AMT STORE$MNR2CST.AMT%TYPE,
    C_CUBIC_AMT STORE$MNR2CST.CUBIC_AMT%TYPE,
    C_LST_ACTN_DT STORE$MNR2CST.LST_ACTN_DT%TYPE,
    C_EMP_CD STORE$MNR2CST.EMP_CD%TYPE
    TYPE STORE$MNR2CST_TYPE IS TABLE OF STORE$MNR2CST_REC_TYPE
    INDEX BY PLS_INTEGER;
    STORE$MNR2CST_COL STORE$MNR2CST_TYPE;
    V_TOT_REC PLS_INTEGER := 0;
    V_FRT2STORE_EXC_TAB CHAR(1);
    V_TOT_REC_IN_STORE$MNR2CST PLS_INTEGER;
    V_ERR_REC PLS_INTEGER;
    BULK_ERRORS EXCEPTION;
    PRAGMA EXCEPTION_INIT (BULK_ERRORS, -24381);
    BEGIN
    --GETTING DATA FROM FRT2STORE TABLE AND INSERTING INTO THE STORE$MNR2CST TABLE
    SELECT COUNT(1)
    INTO V_TOT_REC_IN_STORE$MNR2CST
    FROM STORE$MNR2CST ;
    IF V_TOT_REC_IN_STORE$MNR2CST = 0 THEN
    OPEN C_FRT2STORE;
    LOOP
    FETCH C_FRT2STORE BULK COLLECT INTO STORE$MNR2CST_COL LIMIT 1000;
    EXIT WHEN STORE$MNR2CST_COL.COUNT = 0;
    V_TOT_REC := STORE$MNR2CST_COL.COUNT;
    IF V_TOT_REC > 0 THEN
    BEGIN
    FORALL I IN STORE$MNR2CST_COL.FIRST..STORE$MNR2CST_COL.LAST SAVE EXCEPTIONS
    INSERT INTO STORE$MNR2CST
    (STORE_CD,
    MNR_CD,
    CST_CD,
    BEG_DT,
    END_DT,
    FAC,
    AMT,
    CUBIC_AMT,
    LST_ACTN_DT,
    EMP_CD
    VALUES
    (STORE$MNR2CST_COL(I).C_STORE_CD,
    STORE$MNR2CST_COL(I).C_MNR_CD,
    STORE$MNR2CST_COL(I).C_CST_CD,
    STORE$MNR2CST_COL(I).C_BEG_DT,
    STORE$MNR2CST_COL(I).C_END_DT,
    STORE$MNR2CST_COL(I).C_FAC,
    STORE$MNR2CST_COL(I).C_AMT,
    STORE$MNR2CST_COL(I).C_CUBIC_AMT,
    STORE$MNR2CST_COL(I).C_LST_ACTN_DT,
    STORE$MNR2CST_COL(I).C_EMP_CD
    COMMIT;
    EXCEPTION WHEN BULK_ERRORS THEN
    OPEN C_FRT2STORE_EXC_TAB;
    FETCH C_FRT2STORE_EXC_TAB INTO V_FRT2STORE_EXC_TAB;
    IF C_FRT2STORE_EXC_TAB%NOTFOUND THEN
    EXECUTE IMMEDIATE ('CREATE TABLE FRT2STORE_EXC AS SELECT * FROM FRT2STORE WHERE 1 = 2');
    END IF;
    CLOSE C_FRT2STORE_EXC_TAB;
    FOR J IN 1..SQL%BULK_EXCEPTIONS.COUNT
    LOOP
    V_ERR_REC := SQL%BULK_EXCEPTIONS(J).ERROR_INDEX;
    EXECUTE IMMEDIATE 'INSERT INTO FRT2STORE_EXC (STORE_CD,MNR_CD,FRT_FAC,DT) VALUES ('
    ||STORE$MNR2CST_COL(V_ERR_REC).C_STORE_CD||','
    ||STORE$MNR2CST_COL(V_ERR_REC).C_MNR_CD||','
    ||STORE$MNR2CST_COL(V_ERR_REC).C_FAC||','
    ||STORE$MNR2CST_COL(V_ERR_REC).C_BEG_DT||')';
    END LOOP;
    COMMIT;
    END;
    STORE$MNR2CST_COL.DELETE;
    END IF;
    END LOOP;
    CLOSE C_FRT2STORE;
    END IF;
    COMMIT;
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('error:- '||SQLERRM);
    END ;
    Could any one tell me how to achive this requirment.
    Thanks,
    Sun

    1. Please format your code using the code tags.
    2. You should never need to code create tables like this "EXECUTE IMMEDIATE ('CREATE TABLE FRT2STORE....". This is often seen when creating temporary tables in non-Oracle database but is a misunderstanding in how to do things in Oracle. You should create them outside of your plsql as permanent objects.
    3. In your example, you should not need dynamic sql like this "EXECUTE IMMEDIATE 'INSERT INTO FRT2STORE_EXC...."
    4. In 10gR2 / 11g, DML Error Logging might be a better solution
    http://www.oracle.com/technology/oramag/oracle/06-mar/o26performance.html

  • FORALL ... SAVE EXCEPTIONS

    Hi folks,
    I want to transfer BULK data from exception_test1 to exception_test2 with FORALL ... SAVE EXCEPTIONS
    procedure execute successfull but no data transfer & no exception raise..
    create or replace
    PROCEDURE forall_exception
    AS
    TYPE t_tab IS TABLE OF exception_test1%ROWTYPE;
    l_tab t_tab := t_tab();
    l_error_count NUMBER;
    ex_dml_errors EXCEPTION;
    PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381); --24381
    -- Perform a bulk operation.
    BEGIN
    FORALL i IN l_tab.first .. l_tab.last SAVE EXCEPTIONS
    INSERT INTO exception_test2
    VALUES l_tab(i);
    EXCEPTION
    WHEN ex_dml_errors THEN
    l_error_count := SQL%BULK_EXCEPTIONS.count;
    DBMS_OUTPUT.put_line('Number of failures: ' || l_error_count);
    FOR i IN 1 .. l_error_count LOOP
    DBMS_OUTPUT.put_line('Error: ' || i ||
    ' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index ||
    ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    -- END;
    END;

    Hi,
    You have declared the collection. To get the data into the collection, you need to fetch the data into it and then use it later.
    Modify your code to something like:
    create or replace PROCEDURE forall_exception (in_key_val in number)
    AS
    TYPE t_tab IS TABLE OF exception_test1%ROWTYPE;
    l_tab t_tab := t_tab();
    l_error_count NUMBER;
    ex_dml_errors EXCEPTION;
    PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381); --24381
    -- Perform a bulk operation.
    BEGIN
    SELECT * BULK COLLECT INTO l_tab FROM exception_test1 WHERE key_val = in_key_val;
    FORALL i IN l_tab.first .. l_tab.last SAVE EXCEPTIONS
    INSERT INTO exception_test2 VALUES l_tab(i);
    EXCEPTION
    WHEN ex_dml_errors THEN
    l_error_count := SQL%BULK_EXCEPTIONS.count;
    DBMS_OUTPUT.put_line('Number of failures: ' || l_error_count);
    FOR i IN 1 .. l_error_count LOOP
         DBMS_OUTPUT.put_line('Error: ' || i ||
              ' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index ||
              ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    END;
    /With this, you will have the record fetched into collection l_tab. If any exception occurs, those exceptions will be saved and printed later.

  • Oracle 9i Problem when using multicolumn bulk update with "save exceptions"

    I'm running into a problem with Oracle 9i when running a multicolumn update with "save exceptions". The problem occurs when updating 4 or more fileds. (The data being updated are 40 character text strings)
    I'm updating 1000 records at a time, in bulk.
    The problem goes away when I don't use "save exception" (i.e. catch the exception the normal "pre-Oracle 9i" way) or when I use "save exception" with 3 or fewer fields.
    (I don't get any exceptions when running without the "save exception")
    Thanks

    The problem is an ORA-14403 error detected during bulk updates only when "save exception" is used with more than 3 fields being updated.
    Remove the "save exception" I can update any number of fields.
    or
    Reduce the number of fields being updated to 3 or less and use save exceptions and the 14403 error goes away.
    (I'd like to use "save exception" without having to break the "update" into two separate 3 field updates.)
    Thanks,
    Len

  • Save Exception

    I have used save exception in a FORALL statement and the common error I return is ORA-20000.
    However I get no associated error code. Is this becvause the error is user defined in the db?
    The exception handler is as follows is as follows:
    WHEN bulk_errors THEN
    FOR j IN 1 .. SQL%BULK_EXCEPTIONS.COUNT
    LOOP
    dbms_output.put_line
    ('Error ' || j || ' at iteration ' ||SQL%BULK_EXCEPTIONS(j).ERROR_INDEX || ' desc ' ||pono_tab(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX)||'/'||poli_tab(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX));
    dbms_output.put_line(' OR Err ' ||SQLERRM(-1 * SQL%BULK_EXCEPTIONS(j).ERROR_CODE));
    END LOOP;

    I suppose that's what I should be trying to track down...where the error is actually occurring!!
    Thanks for your interest.
    I will try and run the update without the bulk bind and see if the error stack is more informative.
    PS.
    The application is riddled with inconsistancies in how errors are handled so I am not holding out much hope!!

  • Changing exception clause in method signature when overwriting a method

    Hi,
    I stumbled upon a situation by accident and am not really clear on the details surrounding it. A short description:
    Say there is some API with interfaces Foo and Bar as follows:
    public interface Foo {
       void test() throws Exception;
    public interface Bar extends Foo {
       void test();
    }Now, I find it strange that method test() for interface Bar does not need to define Exception in its throws clause. When I first started with Java I was using Java 1.4.2; I now use Java 1.6. I cannot remember ever reading about this before and I have been unable to find an explanation or tutorial on how (or why) this works.
    Consider a more practical example:
    Say there is an API that uses RMI and defines interfaces as follwows:
    public interface RemoteHelper extends Remote {
       public Object select(int uid) throws RemoteException;
    public interface LocalHelper extends RemoteHelper {
       public Object select(int uid);
    }As per the RMI spec every method defined in a Remote interface must define RemoteException in its throws clause. The LocalHelper cannot be exported remotely (this will fail at runtime due to select() in LocalHelper not having RemoteException in its clause if I remember correctly).
    However, an implementing class for LocalHelper could represent a wrapper class for RemoteHelper, like this:
    public class Helper implements LocalHelper {
       private final RemoteHelper helper;
       public Helper(RemoteHelper helper) {
          this.helper = helper;
       public Object select(int id) {
          try {
             return (this.helper.select(id));
          } catch(RemoteException e) {
             // invoke app failure mechanism
    }This can uncouple an app from RMI dependancy. In more practical words: consider a webapp that contains two Servlets: a "startup" servlet and an "invocation" servlet. The startup servlet does nothing (always returns Method Not Allowed, default behaviour of HttpServlet), except locate an RMI Registry upon startup and look up some object bound to it. It can then make this object accessible to other classes through whatever means (i.e. a singleton Engine class).
    The invocation servlet does nothing upon startup, but simply calls some method on the previously acquired remote object. However, the invocation servlet does not need to know that the object is remote. Therefore, if the startup servlet wraps the remote object in another object (using the idea described before) then the invocation servlet is effectively removed from the RMI dependancy. The wrapper class can invoke some sort of failure mechanism upon the singleton engine (i.e. removing the remote object from memory) and optionally throw some other (optionally checked) exception (i.e. IllegalStateException) to the invocation servlet.
    In this way, the invocation servlet is not bound to RMI, there can be a single point where RemoteExceptions are handled and an unchecked exception (i.e. IllegalStateException) can be handled by the Servlet API through an exception error page, displaying a "Service Unavailable" message.
    Sorry for all this extensive text; I just typed out some thoughts. In short, my question is how and why can the throws clause change when overwriting a method? It's nothing I need though, except for the clarity (e.g. is this a bad practice to do?) and was more of an observation than a question.
    PS: Unless I'm mistaken, this is basically called the "Adapter" or "Bridge" (not sure which one it is) pattern (or a close adaptation to it) right (where one class is written to provide access to another class where the method signature is different)?
    Thanks for reading,
    Yuthura

    Yuthura wrote:
    I know it may throw any checked exception, but I'm pretty certain that an interface that extends java.rmi.Remote must include at least java.rmi.RemoteException in its throws clause (unless the spec has changed in Java 1.5/1.6).No.
    A method can always throw fewer exceptions than the one it's overriding. RMI has nothing to do with it.
    See Deitel & Deilte Advanced Java 2 Platform How To Program, 1st Ed. (ISBN 0-13-089650-1), page 793 (sorry, I couldn't find the RMI spec quick enough). Quote: "Each method in a Remote interface must have a throws clause that indicates that the method can throw RemoteException".Which means that there's always a possibility of RemoteException being thrown. That's a different issue. It's not becusae the parent class can throw RE. Rather, it's because some step that will always be followed is declared to throw RE.
    I later also noticed I could not add other checked exceptions, which made sense indeed. Your explanation made perfect sense now that I heard (read) it. But just to humour my curousity, has this always been possible? Yes, Java has always worked that way.
    PS: The overwriting/-riding was a grammatical typo (English is not my native language), but I meant to say what you said.No problem. Minor detail. It's a common mistake, but I always try to encourage proper terminology.

  • Exception Handling for inserts

    Hi,
    My requirement is to populate a table with values got by selecting columns from various table on join conditions. It works fine if all the rows inserted are unique. However if the row to be inserted is duplicate, it violates the uniqueness constraint.
    I want an exception wherein if select query returns 100 rows, of which 80 are already there in the table to be populated, it should just insert the 20 records.
    Below is the SP i wrote for the same. However, as soon as it meets exception condition, it just prints the condition and exits, without processing the rest of the records. Please look at the SP below and suggest a solution.
    create or replace
    PROCEDURE PP_CMC_TEST AS
    cursor c1 is
    (select cdu.subscription_id,max(cdu.account_id),max(s.subscription_versn_start_date),
    max(s.service_plan_id),max(sbp.billing_period_id),sysdate-1
    ,cdu.device_name, cdu.resource_id,sum(cdu.usage),max(cdu.unit_of_measurement)
    from
    subscriptions s, subscription_billing_period sbp, consolidated_daily_usage cdu
    where s.version_end_date is null and
    sysdate-1 between sbp.start_date and sbp.end_date and
    cdu.usage_date between sbp.start_date and sbp.end_date
    and s.subscription_id = cdu.subscription_id
    and sbp.subscription_id = cdu.subscription_id
    and sbp.subscription_id = s.subscription_id
    and s.subscription_versn_start_date=sbp.subscription_versn_start_date
    group by cdu.subscription_id,cdu.device_name, cdu.resource_id);
    a number;
    b number;
    c date;
    d number;
    e number;
    f date;
    g varchar2 (255);
    h number;
    i number;
    j varchar2(60);
    BEGIN
      OPEN c1;
        LOOP
            FETCH c1 INTO a,b,c,d,e,f,g,h,i,j;
             EXIT WHEN c1%NOTFOUND;
    insert into cmc_test
    (subscription_id,account_id,subscription_versn_start_date,service_plan_id,billing_period_id,curr_date,
    device_name,resource_id,usage,unit_of_measurement) values
    (a,b,c,d,e,f,g,h,i,j);
        END LOOP; 
                                 EXCEPTION
        WHEN DUP_VAL_ON_INDEX
          THEN
          DBMS_OUTPUT.PUT_LINE('DUPLICATE RECORD FOUND');
          commit;
        CLOSE c1; 
    END PP_CMC_TEST;Edited by: BluShadow on 07-Feb-2012 09:03
    added {noformat}{noformat} tags (for what it was worth).  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Using SQL you would create an error table and modify the INSERT to log the errors. See the 'Inserting Into a Table with Error Logging' section of http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9014.htm. Note this approach will not work if you are using direct path loads since the log table won't be used.
    If you are going to use PL/SQL for this then what you want is to use BULK COLLECT and then a FORALL with a SAVE EXCEPTIONS clause.
    >
    A. BULK COLLECT INTO plsqlTable LIMIT 5000 - These are your new records you want to INSERT
    B. FORALL ... SAVE EXCEPTIONS - This is the INSERT query to insert the new records
    C. Use a bulk exception handler. Any record in the FORALL that causes an exception will have it's index put into the bulk exception array. In the bulk exception handler you can loop through the array and access the records that caused the error using the index into the plsqlTable and do any error logging you need to do.
    >
    The bulk exception array will have the plsql table index of the row that caused the error. You can index into the plsql table (see Step A above) to access the record and then log it, INSERT it into a duplicates table or whatever you want.
    The important thing is that the records that do not have errors will still get processed. Similar result to what will happen if you use SQL and an error table.

  • Forall exception rollback

    Hi Guys,
    I have a forall statement that I want to continue processing if it hits an exception, and rollback anything it fails on. I have limits set so I am only lifting 300 records at a time, but if only one record fails in the forall, then i want the other 299 to process and commit, and only rollback that one failure..is it possible? This is using oracle 10g.
    Example snippet below, the "dots" are just were I have removed unneeded code for this example. I want to know if I can add a rollback in the EXCEPTION that will rollback the forall failure for the one saved exception, and the "commit" will commit the remaining 299 that were success?
    BEGIN
    LOOP
    FETCH cursor1
    BULK COLLECT INTO table1 LIMIT 300;
    IF table1.COUNT > 0
    THEN
    BEGIN
    FORALL i IN 1 .. table1.COUNT SAVE EXCEPTIONS
    END IF;
    EXIT WHENtable1.COUNT = 0;
    table1.DELETE;
    END LOOP;
    CLOSE cursor1;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN
    ROLLBACK;
    END;
    Edited by: fixxxer on 13-Oct-2011 01:36

    You can not do INSERT and DELETE using same FORALL statelemt. For that you have to create seperate copy of Collection.
    If you want to ROLLBACK everything thnen omit the SAVE EXCEPTION statement in FORALL.
    You can gothrough below FORALL restriction...
    Restrictions
    The following restrictions apply to the FORALL statement:
    •You cannot loop through the elements of an associative array that has a string type for the key.
    •Within a FORALL loop, you cannot refer to the same collection in both the SET clause and the WHERE clause of an UPDATE statement. You might need to make a second copy of the collection and refer to the new name in the WHERE clause.
    •You can use the FORALL statement only in server-side programs, not in client-side programs.
    •The INSERT, UPDATE, or DELETE statement must reference at least one collection. For example, a FORALL statement that inserts a set of constant values in a loop raises an exception.
    •When you specify an explicit range, all collection elements in that range must exist. If an element is missing or was deleted, you get an error.
    •When you use the INDICES OF or VALUES OF clauses, all the collections referenced in the DML statement must have subscripts matching the values of the index variable. Make sure that any DELETE, EXTEND, and so on operations are applied to all the collections so that they have the same set of subscripts. If any of the collections is missing a referenced element, you get an error. If you use the SAVE EXCEPTIONS clause, this error is treated like any other error and does not stop the FORALL statement.
    •You cannot refer to individual record fields within DML statements called by a FORALL statement. Instead, you can specify the entire record with the SET ROW clause in an UPDATE statement, or the VALUES clause in an INSERT statement.
    •Collection subscripts must be just the index variable rather than an expression, such as i rather than i+1.
    •The cursor attribute %BULK_ROWCOUNT cannot be assigned to other collections, or be passed as a parameter to subprograms.

  • How to view errors if bulk collect has thrown errors

    Hi,
    I have few questions.
    1.How to view error whether bulk collect is successful or not
    2.What is identified & unidentified relationships in ERWIN
    3.How to see the errors whether the sql loder is successful or not
    and how to open the log file.Is there any specific command in UNIX
    which tells loader is successful or thrown error
    4.When executing the pl/sql procedure from UNIX.how to check for errors.
    Please provide the answers for this
    Thanks

    Use SAVE EXCEPTIONS clause in your FORALL loop.
    Is this for homework/test?

  • How can I run two DML in one FORALL statement?

    How can I run 1) select 2) update in one FORALL for each item as below?
    OPEN FXCUR;
      LOOP
            FETCH FXCUR BULK COLLECT INTO v_ims_trde_oids LIMIT 1000;
            EXIT  WHEN v_ims_trde_oids.COUNT() = 0;
         FORALL i IN v_ims_trde_oids.FIRST .. v_ims_trde_oids.LAST     
              SELECT EXTRACTVALUE(XMLTYPE(CNTNT),'/InboundGTMXML/ProcessingIndicators/ClientCLSEligibleIndicator')        INTO v_cls_ind
              FROM IMS_TOMS_MSGE  WHERE ims_trde_oid = v_ims_trde_oids(i);
             IF v_cls_ind      IS NOT NULL THEN
                      v_cls_ind       := '~2136|S|'||v_cls_ind||'|';
             UPDATE ims_alctn_hstry  SET CHNGE_DATA_1   =concat(CHNGE_DATA_1,v_cls_ind)
             WHERE ims_trde_hstry_id = (select max(ims_trde_hstry_id) from ims_alctn_hstry where ims_trde_oid=v_ims_trde_oids(i));
             DBMS_OUTPUT.PUT_LINE('Trade oid: '||v_ims_trde_oids(i)||'   CLS Eligible Indicator: '||v_cls_ind);
          END IF;
      END LOOP;
      CLOSE FXCUR;Your help will be appreciated.
    Thanks
    Edited by: PhoenixBai on Aug 6, 2010 6:05 PM

    I came through this forum while googling on the issue of 'using two DML's in one FORALL statement.
    Thanks for all the useful information guys.
    I need to extend this functionality a bit.
    My present scenario is as follows:
    FOR I in 1..collection1.count Loop
         BEGIN
              insert into tab1(col1)
              values collection1(I) ;
         EXCEPTION
              WHEN OTHERS THEN
              RAISE_APPLICATION_ERROR('ERROR AT'||collection1(I));
         END;
         BEGIN
              UPDATE tab2
              SET col1 = collection1(I);
         EXCEPTION
              WHEN OTHERS THEN
              RAISE_APPLICATION_ERROR('ERROR AT'||collection1(I));
         END;
    commit;
    END LOOP;
    I need to use the FORALL functionality in this scenario, but without using the SAVE EXCEPTIONS clause keeping in mind that I also need to get value in the
    collection that led to the error.Also, the each INSERT statement has to be followed by an UPDATE and then the cycle goes on(Hence I cannot use 2 FORALL statements for INSERT and UPDATE coz then all the INSERT will be performed at once and similarly the UPDATEs). So I created something like this:
    DECLARE
    l_stmt varchar2(1000);
    BEGIN
    l_stmt := 'BEGIN '||
              'insert into tab1(col1) '||
              'values collection1(I) ; '||
         'EXCEPTION '||
              'WHEN OTHERS THEN '||
              'RAISE_APPLICATION_ERROR(''ERROR AT''|| :1); '||
         'END; '||
         'BEGIN '||
              'UPDATE tab2 '||
              'SET col1 = :1; '||
         'EXCEPTION '||
              'WHEN OTHERS THEN '||
              'RAISE_APPLICATION_ERROR(''ERROR AT''|| :1); '||
         'END;'
    FORALL I in 1..collection1.count
    EXECUTE IMMEDIATE l_stmt USING Collection1(SQL%BULK_EXCEPTIONS(1).ERROR_INDEX);
    END;
    Will this approach work? Or is there any better aproach to this? I am trying to avoid the traditional FOR ..LOOP to achieve better performance of query

  • Deadlock issue in Partitioned Tables

    Hi ALL,
    I am facing an issue of Deadlock while inserting data into a partitioned table.
    I get an error "ORA-00600: Deadlock detected". when i see the trace files, following lines are appearing in them:
    "Single resource deadlock: blocking enqueue which blocks itself".
    Here is the detail of my test case:
    1. I have a list-partitioned table, with partitioning defined on some business codes.
    2. I have a query that merges data into partitioned table (actually compares unique keys between temporary table and partitioned table and then issue an insert if keys not matched, no update part).
    3. The temporary table contains transactional data against many business codes.
    3. when calling the above query from multiple (PL/SQL) sessions, i observe that when we merge data in same partition (from different sessions) than deadlock issue occurs, otherwise it is OK.
    4. Note that all sessions are executed at same time. Also note that Commit is called after each session is completed. Each session contains 2-3 more queries after the mentioned merge statement.
    Is there an issue with oracle merge/insert on same partition (from different sessions)? What is the locking mechanism for this particular case (partitioned tables)?
    My oracle version is Oracle 10g (10.2.0.4). Kindly advice.
    Thanks,
    QQ.

    Oracle MERGE statements are slow as they must validate every record before insert.
    If you use array processing with BULK COLLECT and FORALL with the SAVE EXCEPTIONS clause you can avoid most of the overhead. Just collect your rows in an array, issue a FORALL INSERT SAVE EXCEPTIONS and let Oracle handle whatever happens.
    When Oracle is done, and it will be hundreds of times faster than what you are doing now, you can either process or ignore the records in the exceptions array.
    Another solution, more efficient if you can do it, is to just to an INSERT INTO SELECT FROM using an exceptions table created with DBMS_ERRLOG.
    www.psoug.org/reference/dbms_errlog.html

  • How to handle the bad record while using bulk collect with limit.

    Hi
    How to handle the Bad record as part of the insertion/updation to avoid the transaction.
    Example:
    I am inserting into table with LIMIT of 1000 records and i've got error at 588th record.
    i want to commit the transaction with 588 inserted record in table and log the error into
    error logging table then i've to continue with transaction with 560th record.
    Can anyone suggest me in this case.
    Regards,
    yuva

    >
    How to handle the Bad record as part of the insertion/updation to avoid the transaction.
    >
    Use the SAVE EXCEPTIONS clause of the FORALL if you are doing bulk inserts.
    See SAVE EXCEPTIONS in the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm
    And then see Example 12-9 Bulk Operation that continues despite exceptions
    >
    Example 12-9 Bulk Operation that Continues Despite Exceptions
    -- 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;
    -- 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 job_id of 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 errors occurred during FORALL SAVE EXCEPTIONS,
    -- a single exception is raised when the statement completes.
    EXCEPTION
    -- Figure out what failed and why
    WHEN dml_errors THEN
    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;
    DROP TABLE emp_temp;

Maybe you are looking for

  • Template for Adhoc Query

    Hi I need to create a role  so that user can create and execute adhoc query. Please let me know the template that can be copied in this regard in BI Thanks in advance

  • The text in my hotmail is very large i need to make it smaller

    The text in hotmail is very large i would like to know how to make the text normal size. The troubleshooting information did not help. == Yesterday

  • Edit in place and versioning

    Hi Having built a very fast network to make use of 'Edit In Place' we are surprised to see that Edit in place does not appear to support versioning? i.e we want to drag out a project, work on it and then drag it back into FCserver, where a new versio

  • Getting servlet context in a web service

    Hi, I have a problem but have no solution to it and am not sure of the approach. I am creating a web service. Some parameters will be passed to this web service. I need to capture these parameters and put it in a hash table so that it is available to

  • Porque aparece sin sim cuando la sim esta insertada?

    IPhone 5s, IOS 8.1 aparece en la pantalla "sin sim". La tarjeta sim esta insertada correctamente