Forall exception

Hi all,
What would heppen if forall statement fails in procedure.
How to handle it in the exception handling section.
Kindly help me .
thank you
regards
P Prakash

Hi friend,
May be it is related to Collections Exception Handler Problem.Please check once using Collections Exception Handlers.
Internally it maintain collections while inserting the data.I am not sure just try it.
Thanks,
Sanjeev.

Similar Messages

  • FORALL Exception handling problem

    Hi All,
    I have one doubt in forall exception handling. I have gone through the SAVE EXCEPTION for bulk collect but i have one more query
    BEGIN
    FORALL j IN l_tab.first .. l_tab.last
    INSERT INTO exception_test
    VALUES (l_tab(i));
    EXCEPTION
    END;
    My requirement is when an exception occurs, i ant to print the values of the collection.
    e.g. say l_tab (j).emp_number, l_tab (j).emp_id.
    How is that possible?
    Thanks
    Samarth
    Edited by: 950810 on Mar 12, 2013 7:28 PM

    >
    I have one doubt in forall exception handling. I have gone through the SAVE EXCEPTION for bulk collect but i have one more query
    BEGIN
    FORALL j IN l_tab.first .. l_tab.last
    INSERT INTO exception_test
    VALUES (l_tab(i));
    EXCEPTION
    END;
    My requirement is when an exception occurs, i ant to print the values of the collection.
    e.g. say l_tab (j).emp_number, l_tab (j).emp_id.
    How is that possible?
    >
    Post the code you are using. You didn't post the FORALL that is using SAVE EXCEPTIONS.
    The SQL%BULK_EXCEPTIONS associative array that you get has the INDEX of the collection element that caused the exception.
    So you need to use those indexes to index into the original collection to get whatever values are in it.
    One index from the exception array is:
    SQL%BULK_EXCEPTIONS(i).error_index So if your original collection is named 'myCollection' you would reference that collection value as:
    myCollection(SQL%BULK_EXCEPTIONS(i).error_index); See 'Handling FORALL Exceptions (%BULK_EXCEPTIONS Attribute)' in the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i49099
    >
    All exceptions raised during the execution are saved in the cursor attribute %BULK_EXCEPTIONS, which stores a collection of records. Each record has two fields:
    %BULK_EXCEPTIONS(i).ERROR_INDEX holds the iteration of the FORALL statement during which the exception was raised.
    %BULK_EXCEPTIONS(i).ERROR_CODE holds the corresponding Oracle Database error code.
    The values stored by %BULK_EXCEPTIONS always refer to the most recently executed FORALL statement. The number of exceptions is saved in %BULK_EXCEPTIONS.COUNT. Its subscripts range from 1 to COUNT.
    The individual error messages, or any substitution arguments, are not saved, but the error message text can looked up using ERROR_CODE with SQLERRM as shown in Example 12-9.
    You might need to work backward to determine which collection element was used in the iteration that caused an exception. For example, if you use the INDICES OF clause to process a sparse collection, you must step through the elements one by one to find the one corresponding to %BULK_EXCEPTIONS(i).ERROR_INDEX. If you use the VALUES OF clause to process a subset of elements, you must find the element in the index collection whose subscript matches %BULK_EXCEPTIONS(i).ERROR_INDEX, and then use that element's value as the subscript to find the erroneous element in the original collection.

  • 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.

  • Bulk exception error

    Hi All,
    my procedure is like this ...
    CREATE OR REPLACE PROCEDURE nested_proc
    IS
    CURSOR cur_TEMPVARRAY
    IS
    SELECT * FROM TEMPVARRAY;
    TYPE typ_TEMPVARRAY IS TABLE OF cur_TEMPVARRAY%ROWTYPE;
    r_TEMPVARRAY typ_TEMPVARRAY;
    --v_TEMPVARRAY TEMPVARRAY%rowtype;
    error_count number;
    dml_error exception;
    pragma exception_init(dml_error,-20902);
    BEGIN
    --pmytab ('inserted-1');
    -- execute immediate 'truncate table cp_tempvarray';
    OPEN cur_TEMPVARRAY;
    LOOP
    FETCH cur_TEMPVARRAY BULK COLLECT INTO r_TEMPVARRAY limit 10;
    FORALL i_tp IN r_TEMPVARRAY.FIRST .. r_TEMPVARRAY.LAST save exceptions
    -- INSERT INTO cp_tempvarray
    -- VALUES r_TEMPVARRAY (i_tp);
    INSERT INTO cp_tempvarray
    VALUES (r_TEMPVARRAY (i_tp).a,
    r_TEMPVARRAY (i_tp).b,
    r_TEMPVARRAY (i_tp).c,
    r_TEMPVARRAY (i_tp).d,
    r_TEMPVARRAY (i_tp).e,
    r_TEMPVARRAY (i_tp).f,
    r_TEMPVARRAY (i_tp).g,
    r_TEMPVARRAY (i_tp).h,
    r_TEMPVARRAY (i_tp).i,
    r_TEMPVARRAY (i_tp).j,
    r_TEMPVARRAY (i_tp).j);
    -- pmytab ('inserted1');
    EXIT WHEN cur_TEMPVARRAY%NOTFOUND;
    END LOOP;
    COMMIT;
    CLOSE cur_TEMPVARRAY;
    COMMIT;
    EXCEPTION
    WHEN DML_ERROR THEN
    error_count :=sql%bulk_exceptions.count;
    DBMS_OUTPUT.put_line('Number of failures: ' || error_count);
    for bulk_err in 1 .. error_count
    loop
    dbms_output.put_line('error' || bulk_err ||
    'array index'||sql%bulk_exceptions(bulk_err).error_index||
    'Massage'||sqlerrm(-sql%bulk_exceptions(bulk_err).error_code));
    end loop;
    END nested_proc;
    when i am executing this procedure, i am getting the below error+
    SQL> execute nested_proc;
    ERROR:
    ORA-24381: error(s) in array DML
    ORA-06512: at "VRESS.NESTED_PROC", line 18
    ORA-06512: at line 1
    can any body help me plzzz..
    Thanks,
    Krupa

    >
    ORA-06512: at "VRESS.NESTED_PROC", line 18
    >
    One or more rows of your FORALL failed and you didn't trap the exception so your code blew up.
    When bulk processing with FORALL you need to trap the bulk exception if you want processing to continue if an error is encountered with one of the records.
    You are trapping AN exception
    pragma exception_init(dml_error,-20902);but that is not the bulk exception that you need to trap. You need to trap ORA-24381.
    >
    Example 12-9 shows how you can perform a number of DML operations, without stopping if some operations encounter errors. In the example, EXCEPTION_INIT is used to associate the DML_ERRORS exception with the predefined error ORA-24381. ORA-24381 is raised if any exceptions are caught and saved after a bulk operation.
    >
    See Handling FORALL Exceptions in the PL/SQL Language Reference
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i49099

  • How can I see error when  execute UPDATE with BULK COLLECT

    Hi
    I have a code
       CURSOR c_renov_eleg IS
            SELECT t2.ROWID
              FROM mytable  t2
         WHERE  BLA BLA BLA
    OPEN c_renov_eleg;
          LOOP
            FETCH c_renov_eleg BULK COLLECT
              INTO w_rowid LIMIT 1000;
            FORALL i IN 1 .. w_rowid.COUNT
              UPDATE mytable
                 SET id_baixa_elegibilidade = K_SCNOB_BXA_RENOVACAO,
                      column01         = arr_ciclo(1),
                     dt_ultima_atualizacao  = SYSDATE,
                     cd_usuario_atualizacao = USER
               WHERE ROWID = w_rowid(i);
            COMMIT;
            EXIT WHEN c_renov_eleg%NOTFOUND;
          END LOOP;How can I to sse when and where have some error ? , in Exception return what record ?

    How can I to sse when and where have some error
    ?Have a look at
    [url=http://download.oracle.com/docs/cd/B28359_01/appd
    ev.111/b28370/tuning.htm#i49099]Handling FORALL
    Exceptions (%BULK_EXCEPTIONS Attribute).btw. just never ever commit in a for loop ;)
    (Tubby is just too fast ;))
    Hi , thank all
    btw. just never ever commit in a for loopWhen I must to COMMIT using BULK COLLECT ?

  • Exceptional handling using Bulk Collect FORALL

    Hi Members,
    Following are by DB details
    SELECT * FROM v$version;                 
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE     9.2.0.7.0     Production
    TNS for HPUX: Version 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - ProductionI need to handle exception during Bulk Collect FORALL operation and update the table column with Status_flag as 'E' for given item name and extension id. Below is the code snippet for the same.
    declare
      k  NUMBER;
    cursor c_list_price
    IS
    SELECT  /*+ leading(a)  */    item_name,
                             'PUBLISH_TO_PRICE_CATALOG' ATTRIBUTE_NAME,
                             MAX(DECODE (attribute_name,
                                         'PUBLISH_TO_PRICE_CATALOG',
                                         attribute_value))
                                ATTRIBUTE_VALUE,
                             NULL GEOGRAPHY_LEVEL,
                             NULL GEOGRAPHY_VALUE,
                             NULL INCLUDE_GEOGRAPHY,
                             NULL EFFECTIVE_START_DATE,
                             NULL EFFECTIVE_TO_DATE,
                             EXTENSION_ID,
                             NULL PRICING_UNIT,
                             NULL ATTRIBUTE_FROM,
                             NULL ATTRIBUTE_TO,
                             NULL FIXED_BASE_PRICE,
                             NULL PARENT_ATTRIBUTE,
                             NULL DURATION_QUANTITY,
                             NULL ATTRIBUTE2,
                             NULL ATTRIBUTE3,
                             NULL ATTRIBUTE4,
                             NULL ATTRIBUTE5,
                             NULL ATTRIBUTE6,
                             NULL ATTRIBUTE7,
                             NULL ATTRIBUTE8,
                             NULL ATTRIBUTE9,
                             NULL ATTRIBUTE10,
                             NULL ATTRIBUTE11,
                             NULL ATTRIBUTE12,
                             NULL ATTRIBUTE13,
                             NULL ATTRIBUTE14,
                             NULL ATTRIBUTE15,
                             --ORG_CODE,
                             ITEM_CATALOG_CATEGORY ITEM_CATEGORY,
                             a.INVENTORY_ITEM_ID INVENTORY_ITEM_ID
                      FROM   XXCPD_ITM_SEC_UDA_DETAILS_TB a
                     WHERE   DECODE(attribute_group_name,'LIST_PRICE',DECODE(STATUS_FLAG,'E',1,'P',2,3)
                                                                                                       ,'XXITM_FORM_PRICING_HS',DECODE(STATUS_FLAG,'E',4,'P',5,6)
                                                                                                       ,'XXITM_FORM_PRICING_SB',DECODE(STATUS_FLAG,'E',4,'P',5,6)
                                                                                                       ,'XXITM_ADV_FORM_PRICING_HS',DECODE(STATUS_FLAG,'E',7,'P',8,9)
                                                                                                       ,'XXITM_ADV_FORM_PRICING_SB',DECODE(STATUS_FLAG,'E',7,'P',8,9)
                                                                                                       ,'XXITM_ADV_FORM_PRICING_HWSW',DECODE(STATUS_FLAG,'E',10,'P',11,12)
                                                                                                       ,'XXITM_ADV_FORM_PRICING_SWSUB',DECODE(STATUS_FLAG,'E',10,'P',11,12)
                                                                                                       ,'XXITM_ROUTE_TO_MARKET',DECODE(STATUS_FLAG,'E',13,'P',14,15)) in (1,2,3)
                             AND exists(select /*+ no_merge */  '1' from mtl_system_items_b b where a.inventory_item_id=b.inventory_item_id and b.organization_id=1)
                  GROUP BY   item_name,
                             extension_id,
                             ITEM_CATALOG_CATEGORY,
                             INVENTORY_ITEM_ID;
    TYPE myarray IS TABLE OF c_list_price%ROWTYPE;
    c_lp myarray;
    BEGIN
      OPEN c_list_price;
      LOOP
      FETCH  c_list_price BULK COLLECT INTO  c_lp
                                      LIMIT 50000;
      IF c_lp.count = 0 THEN
        EXIT;
      END IF;
      Begin
      FORALL i IN c_lp.FIRST..c_lp.LAST SAVE EXCEPTIONS
        INSERT /*+append*/ INTO XXCPD_ITEM_PRICING_ATTR_BKP2(
                                                                   line_id,
                                                                   ITEM_NAME,
                                                                   ATTRIBUTE_NAME,
                                                                   ATTRIBUTE_VALUE,
                                                                   GEOGRAPHY_LEVEL,
                                                                   GEOGRAPHY_VALUE,
                                                                   INCLUDE_GEOGRAPHY,
                                                                   EFFECTIVE_START_DATE,
                                                                   EFFECTIVE_TO_DATE,
                                                                   EXTENSION_ID,
                                                                   PRICING_UNIT,
                                                                   ATTRIBUTE_FROM,
                                                                   ATTRIBUTE_TO,
                                                                   FIXED_BASE_PRICE,
                                                                   PARENT_ATTRIBUTE,
                                                                   DURATION_QUANTITY,
                                                                   ATTRIBUTE2,
                                                                   ATTRIBUTE3,
                                                                   ATTRIBUTE4,
                                                                   ATTRIBUTE5,
                                                                   ATTRIBUTE6,
                                                                   ATTRIBUTE7,
                                                                   ATTRIBUTE8,
                                                                   ATTRIBUTE9,
                                                                   ATTRIBUTE10,
                                                                   ATTRIBUTE11,
                                                                   ATTRIBUTE12,
                                                                   ATTRIBUTE13,
                                                                   ATTRIBUTE14,
                                                                   ATTRIBUTE15,
                                                                   ITEM_CATEGORY,
                                                                   INVENTORY_ITEM_ID
                                                            VALUES
                                                                   xxcpd.xxcpd_if_prc_line_id_s.NEXTVAL
                                                                  ,c_lp(i).ITEM_NAME
                                                                  ,c_lp(i).ATTRIBUTE_NAME     
                                                                  ,c_lp(i).ATTRIBUTE_VALUE    
                                                                  ,c_lp(i).GEOGRAPHY_LEVEL    
                                                                  ,c_lp(i).GEOGRAPHY_VALUE    
                                                                  ,c_lp(i).INCLUDE_GEOGRAPHY  
                                                                  ,c_lp(i).EFFECTIVE_START_DATE
                                                                  ,c_lp(i).EFFECTIVE_TO_DATE  
                                                                  ,c_lp(i).EXTENSION_ID       
                                                                  ,c_lp(i).PRICING_UNIT       
                                                                  ,c_lp(i).ATTRIBUTE_FROM     
                                                                  ,c_lp(i).ATTRIBUTE_TO       
                                                                  ,c_lp(i).FIXED_BASE_PRICE  
                                                                  ,c_lp(i).PARENT_ATTRIBUTE   
                                                                  ,c_lp(i).DURATION_QUANTITY  
                                                                  ,c_lp(i).ATTRIBUTE2         
                                                                  ,c_lp(i).ATTRIBUTE3         
                                                                  ,c_lp(i).ATTRIBUTE4         
                                                                  ,c_lp(i).ATTRIBUTE5         
                                                                  ,c_lp(i).ATTRIBUTE6         
                                                                  ,c_lp(i).ATTRIBUTE7         
                                                                  ,c_lp(i).ATTRIBUTE8         
                                                                  ,c_lp(i).ATTRIBUTE9         
                                                                  ,c_lp(i).ATTRIBUTE10        
                                                                  ,c_lp(i).ATTRIBUTE11        
                                                                  ,c_lp(i).ATTRIBUTE12        
                                                                  ,c_lp(i).ATTRIBUTE13        
                                                                  ,c_lp(i).ATTRIBUTE14        
                                                                  ,c_lp(i).ATTRIBUTE15        
                                                                  ,c_lp(i).ITEM_CATEGORY      
                                                                  ,c_lp(i).INVENTORY_ITEM_ID
        EXCEPTION
        WHEN OTHERS THEN
        FOR j IN 1..SQL%bulk_exceptions.Count
            LOOP
                        UPDATE XXCPD_ITM_SEC_UDA_DETAILS_TB
                        SET status_flag = 'E',
                            last_updated_by = 1,
                            last_update_date = SYSDATE
                        WHERE item_name = c_lp(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX).item_name
                        AND  extension_id=c_lp(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX).extension_id;
                        COMMIT;
                 IF c_list_price%ISOPEN THEN
                      CLOSE c_list_price;
                 END IF;
                FND_FILE.put_line(FND_FILE.output,'********************Exception Occured*************:-- '||SYSTIMESTAMP);
            END LOOP;
         END;
      END LOOP;
      CLOSE  c_list_price;
        COMMIT;
    end;and I am getting following error
    ORA-06550: line 156, column 47:
    PL/SQL: ORA-00911: invalid character
    ORA-06550: line 152, column 21:
    PL/SQL: SQL Statement ignoredpointing to following lines in exception block for update clause.
    WHERE item_name = c_lp(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX).item_name
                        AND  extension_id=c_lp(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX).extension_id; can some one please help me out with the issue.
    Thanks in Advance

    Have re-written the code in the following manner
    declare
      lv_ITEM_NAME            DBMS_SQL.VARCHAR2S;
      lv_ITEM_CATEGORY        DBMS_SQL.VARCHAR2S;
      lv_INVENTORY_ITEM_ID    DBMS_SQL.NUMBER_TABLE;
      lv_ATTRIBUTE_NAME       DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE_VALUE      DBMS_SQL.VARCHAR2S;
      lv_GEOGRAPHY_LEVEL      DBMS_SQL.VARCHAR2S;
      lv_GEOGRAPHY_VALUE      DBMS_SQL.VARCHAR2S;
      lv_INCLUDE_GEOGRAPHY    DBMS_SQL.VARCHAR2S;
      lv_EFFECTIVE_START_DATE DBMS_SQL.date_table;
      lv_EFFECTIVE_TO_DATE    DBMS_SQL.date_table;
      lv_EXTENSION_ID         DBMS_SQL.NUMBER_TABLE;
      lv_PRICING_UNIT         DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE_FROM       DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE_TO         DBMS_SQL.VARCHAR2S;
      lv_FIXED_BASE_PRICE     DBMS_SQL.NUMBER_TABLE;
      lv_PARENT_ATTRIBUTE     DBMS_SQL.VARCHAR2S;
      lv_DURATION_QUANTITY    DBMS_SQL.NUMBER_TABLE;
      lv_ATTRIBUTE2           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE3           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE4           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE5           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE6           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE7           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE8           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE9           DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE10          DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE11          DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE12          DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE13          DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE14          DBMS_SQL.VARCHAR2S;
      lv_ATTRIBUTE15          DBMS_SQL.VARCHAR2S;
        l_item_name XXCPD_ITM_SEC_UDA_DETAILS_TB.item_name%TYPE;
        l_extension_id XXCPD_ITM_SEC_UDA_DETAILS_TB.extension_id%TYPE;
    cursor c_list_price
    IS
    SELECT  /*+ leading(a)  */    item_name,
                             'PUBLISH_TO_PRICE_CATALOG' ATTRIBUTE_NAME,
                             MAX(DECODE (attribute_name,
                                         'PUBLISH_TO_PRICE_CATALOG',
                                         attribute_value))
                                ATTRIBUTE_VALUE,
                             NULL GEOGRAPHY_LEVEL,
                             NULL GEOGRAPHY_VALUE,
                             NULL INCLUDE_GEOGRAPHY,
                             NULL EFFECTIVE_START_DATE,
                             NULL EFFECTIVE_TO_DATE,
                             EXTENSION_ID,
                             NULL PRICING_UNIT,
                             NULL ATTRIBUTE_FROM,
                             NULL ATTRIBUTE_TO,
                             NULL FIXED_BASE_PRICE,
                             NULL PARENT_ATTRIBUTE,
                             NULL DURATION_QUANTITY,
                             NULL ATTRIBUTE2,
                             NULL ATTRIBUTE3,
                             NULL ATTRIBUTE4,
                             NULL ATTRIBUTE5,
                             NULL ATTRIBUTE6,
                             NULL ATTRIBUTE7,
                             NULL ATTRIBUTE8,
                             NULL ATTRIBUTE9,
                             NULL ATTRIBUTE10,
                             NULL ATTRIBUTE11,
                             NULL ATTRIBUTE12,
                             NULL ATTRIBUTE13,
                             NULL ATTRIBUTE14,
                             NULL ATTRIBUTE15,
                             --ORG_CODE,
                             ITEM_CATALOG_CATEGORY ITEM_CATEGORY,
                             a.INVENTORY_ITEM_ID INVENTORY_ITEM_ID
                      FROM   XXCPD_ITM_SEC_UDA_DETAILS_TB a
                     WHERE   DECODE(attribute_group_name,'LIST_PRICE',DECODE(STATUS_FLAG,'E',1,'P',2,3)
                                                       ,'XXITM_FORM_PRICING_HS',DECODE(STATUS_FLAG,'E',4,'P',5,6)
                                                       ,'XXITM_FORM_PRICING_SB',DECODE(STATUS_FLAG,'E',4,'P',5,6)
                                                       ,'XXITM_ADV_FORM_PRICING_HS',DECODE(STATUS_FLAG,'E',7,'P',8,9)
                                                       ,'XXITM_ADV_FORM_PRICING_SB',DECODE(STATUS_FLAG,'E',7,'P',8,9)
                                                       ,'XXITM_ADV_FORM_PRICING_HWSW',DECODE(STATUS_FLAG,'E',10,'P',11,12)
                                                       ,'XXITM_ADV_FORM_PRICING_SWSUB',DECODE(STATUS_FLAG,'E',10,'P',11,12)
                                                       ,'XXITM_ROUTE_TO_MARKET',DECODE(STATUS_FLAG,'E',13,'P',14,15)) in (1,2,3)
                             AND exists(select /*+ no_merge */  '1' from mtl_system_items_b b where a.inventory_item_id=b.inventory_item_id and b.organization_id=1)
                  GROUP BY   item_name,
                             extension_id,
                             ITEM_CATALOG_CATEGORY,
                             INVENTORY_ITEM_ID;
    BEGIN
      OPEN c_list_price;
      LOOP
      lv_ITEM_NAME.delete;          
      lv_ITEM_CATEGORY.delete;      
      lv_INVENTORY_ITEM_ID.delete;  
      lv_ATTRIBUTE_NAME.delete;     
      lv_ATTRIBUTE_VALUE.delete;    
      lv_GEOGRAPHY_LEVEL.delete;    
      lv_GEOGRAPHY_VALUE.delete;    
      lv_INCLUDE_GEOGRAPHY.delete;  
      lv_EFFECTIVE_START_DATE.delete;
      lv_EFFECTIVE_TO_DATE.delete;  
      lv_EXTENSION_ID.delete;       
      lv_PRICING_UNIT.delete;       
      lv_ATTRIBUTE_FROM.delete;     
      lv_ATTRIBUTE_TO.delete;       
      lv_FIXED_BASE_PRICE.delete;   
      lv_PARENT_ATTRIBUTE.delete;   
      lv_DURATION_QUANTITY.delete;  
      lv_ATTRIBUTE2.delete;         
      lv_ATTRIBUTE3.delete;         
      lv_ATTRIBUTE4.delete;         
      lv_ATTRIBUTE5.delete;         
      lv_ATTRIBUTE6.delete;         
      lv_ATTRIBUTE7.delete;         
      lv_ATTRIBUTE8.delete;         
      lv_ATTRIBUTE9.delete;         
      lv_ATTRIBUTE10.delete;        
      lv_ATTRIBUTE11.delete;        
      lv_ATTRIBUTE12.delete;        
      lv_ATTRIBUTE13.delete;        
      lv_ATTRIBUTE14.delete;        
      lv_ATTRIBUTE15.delete;        
      FETCH  c_list_price BULK COLLECT INTO   lv_ITEM_NAME
                                             ,lv_ATTRIBUTE_NAME     
                                             ,lv_ATTRIBUTE_VALUE    
                                             ,lv_GEOGRAPHY_LEVEL    
                                             ,lv_GEOGRAPHY_VALUE    
                                             ,lv_INCLUDE_GEOGRAPHY  
                                             ,lv_EFFECTIVE_START_DATE
                                             ,lv_EFFECTIVE_TO_DATE  
                                             ,lv_EXTENSION_ID       
                                             ,lv_PRICING_UNIT       
                                             ,lv_ATTRIBUTE_FROM     
                                             ,lv_ATTRIBUTE_TO       
                                             ,lv_FIXED_BASE_PRICE   
                                             ,lv_PARENT_ATTRIBUTE   
                                             ,lv_DURATION_QUANTITY  
                                             ,lv_ATTRIBUTE2         
                                             ,lv_ATTRIBUTE3         
                                             ,lv_ATTRIBUTE4         
                                             ,lv_ATTRIBUTE5         
                                             ,lv_ATTRIBUTE6         
                                             ,lv_ATTRIBUTE7         
                                             ,lv_ATTRIBUTE8         
                                             ,lv_ATTRIBUTE9         
                                             ,lv_ATTRIBUTE10        
                                             ,lv_ATTRIBUTE11        
                                             ,lv_ATTRIBUTE12        
                                             ,lv_ATTRIBUTE13        
                                             ,lv_ATTRIBUTE14        
                                             ,lv_ATTRIBUTE15        
                                             ,lv_ITEM_CATEGORY      
                                             ,lv_INVENTORY_ITEM_ID
                                      LIMIT 50000;
      IF lv_INVENTORY_ITEM_ID.count = 0 THEN
        EXIT;
      END IF;
      Begin
      FORALL I IN 1..lv_INVENTORY_ITEM_ID.count SAVE EXCEPTIONS
        INSERT /*+append*/ INTO XXCPD_ITEM_PRICING_ATTR_BKP2(
                                                                   line_id,
                                                                   ITEM_NAME,
                                                                   ATTRIBUTE_NAME,
                                                                   ATTRIBUTE_VALUE,
                                                                   GEOGRAPHY_LEVEL,
                                                                   GEOGRAPHY_VALUE,
                                                                   INCLUDE_GEOGRAPHY,
                                                                   EFFECTIVE_START_DATE,
                                                                   EFFECTIVE_TO_DATE,
                                                                   EXTENSION_ID,
                                                                   PRICING_UNIT,
                                                                   ATTRIBUTE_FROM,
                                                                   ATTRIBUTE_TO,
                                                                   FIXED_BASE_PRICE,
                                                                   PARENT_ATTRIBUTE,
                                                                   DURATION_QUANTITY,
                                                                   ATTRIBUTE2,
                                                                   ATTRIBUTE3,
                                                                   ATTRIBUTE4,
                                                                   ATTRIBUTE5,
                                                                   ATTRIBUTE6,
                                                                   ATTRIBUTE7,
                                                                   ATTRIBUTE8,
                                                                   ATTRIBUTE9,
                                                                   ATTRIBUTE10,
                                                                   ATTRIBUTE11,
                                                                   ATTRIBUTE12,
                                                                   ATTRIBUTE13,
                                                                   ATTRIBUTE14,
                                                                   ATTRIBUTE15,
                                                                   ITEM_CATEGORY,
                                                                   INVENTORY_ITEM_ID
                                                            VALUES
                                                                   xxcpd.xxcpd_if_prc_line_id_s.NEXTVAL
                                                                  ,lv_ITEM_NAME(i)
                                                                  ,lv_ATTRIBUTE_NAME(i)     
                                                                  ,lv_ATTRIBUTE_VALUE(i)    
                                                                  ,lv_GEOGRAPHY_LEVEL(i)    
                                                                  ,lv_GEOGRAPHY_VALUE(i)    
                                                                  ,lv_INCLUDE_GEOGRAPHY(i)  
                                                                  ,lv_EFFECTIVE_START_DATE(i)
                                                                  ,lv_EFFECTIVE_TO_DATE(i)  
                                                                  ,lv_EXTENSION_ID(i)       
                                                                  ,lv_PRICING_UNIT(i)       
                                                                  ,lv_ATTRIBUTE_FROM(i)     
                                                                  ,lv_ATTRIBUTE_TO(i)       
                                                                  ,lv_FIXED_BASE_PRICE(i)  
                                                                  ,lv_PARENT_ATTRIBUTE(i)   
                                                                  ,lv_DURATION_QUANTITY(i)  
                                                                  ,lv_ATTRIBUTE2(i)         
                                                                  ,lv_ATTRIBUTE3(i)         
                                                                  ,lv_ATTRIBUTE4(i)         
                                                                  ,lv_ATTRIBUTE5(i)         
                                                                  ,lv_ATTRIBUTE6(i)         
                                                                  ,lv_ATTRIBUTE7(i)         
                                                                  ,lv_ATTRIBUTE8(i)         
                                                                  ,lv_ATTRIBUTE9(i)         
                                                                  ,lv_ATTRIBUTE10(i)        
                                                                  ,lv_ATTRIBUTE11(i)        
                                                                  ,lv_ATTRIBUTE12(i)        
                                                                  ,lv_ATTRIBUTE13(i)        
                                                                  ,lv_ATTRIBUTE14(i)        
                                                                  ,lv_ATTRIBUTE15(i)        
                                                                  ,lv_ITEM_CATEGORY(i)      
                                                                  ,lv_INVENTORY_ITEM_ID(i)
        EXCEPTION
        WHEN OTHERS THEN
        ROLLBACK;
        FOR j IN 1..SQL%bulk_exceptions.Count
            LOOP
            l_item_name:=lv_ITEM_NAME(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX);
            l_extension_id:=lv_EXTENSION_ID(SQL%BULK_EXCEPTIONS(j).ERROR_INDEX);
                        UPDATE XXCPD_ITM_SEC_UDA_DETAILS_TB
                        SET status_flag = 'E',
                            last_updated_by = 1,
                            last_update_date = SYSDATE
                        WHERE item_name = l_item_name
                        AND  extension_id=l_extension_id;
                        COMMIT;
                FND_FILE.put_line(FND_FILE.output,'********************Exception Occured*************:-- '||SYSTIMESTAMP);
            END LOOP;
         END;
      END LOOP;
      CLOSE  c_list_price;
        COMMIT;
    end;

  • FORALL and EXCEPTION

    Hello Everyone,
    I have gone through the document also.
    I am using dblink to get data in to table FORALL,
    sometimes the database connection is lost from dblink. , i want to stop the process. and exit the loop, i am handeling the error. it raised three errors
    ORA-02068
    ORA-02063
    ORA-02048
    i read the desciption of the error, i am not sure which one is the correct to hadle. I want to handle this as special error in exception, how can i hadle this excepton.
    i looks like that once the db connection is lost forall stops execution. is that correct? please correct if if i am wrong.
    Please help me.
    thank you in advance

    You will want to map these exceptions using PRAGMA EXCEPTION_INIT and capture them as a user defined exception. You will find an example of doing this here:
    http://www.psoug.org/reference/exception_handling.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.

  • Deletion is taking long time using forall

    Hi,
           i am  inserting and deleting the rows using forall. insert taking less time to inset the rows but while coming to
    deletion it is taking more than 5 days long time to delete 18.5 million rows in a table using forall.
    the main table having 70 million rows.
    the code is..
       FETCH ref_typ  BULK COLLECT INTO l_id_tbl LIMIT 10000;
       begin
        FORALL i in  1..l_id_tbl.COUNT
           INSERT INTO   change_test (id,
                                 history,
                                 transaction,
                                 date)
                         VALUES (seq.nextval,
                                 'CHANGE_HIS',
                                 l_id_tbl(i),
                                 sysdate);
           exception
               when others then
                null;
        end;
        begin
            FoRALL i in 1..l_id_tbl.COUNT
              DELETE FROM change_his
                     where id = l_id_tbl(i);
           exception
               when others then
                 null;
       end;
      end loop;
    so  please give me a good solution  to delete the rows less than 5 days..

    Why are you wanting to do this using BULK COLLECT and FORALL?
    Why not just "insert ... select ..." and "delete ..."?
    Loading records into expensive PGA memory to insert them back on the database is bound to be slower (and use more server resources) than just doing a straight insert ... select ... statement.
    Explain exactly what you are trying to do.
    Re: 2. How do I ask a question on the forums?

  • No Data Found Exception in bulk updates

    I am trying to catch no data found exception in bulk updates when it does not find a record to update in the forall loop.
    OPEN casualty;
    LOOP
    FETCH casulaty
    BULK COLLECT INTO v_cas,v_adj,v_nbr
    LIMIT 10000;
    FORALL i IN 1..v_cas.count
    UPDATE tpl_casualty
         set casualty_amt = (select amt from tpl_adjustment where cas_adj = v_adj(i))
         where cas_nbr = v_nbr(i);
    EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line('exception')
    I get this error at the line where i have exception:
    PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
    begin case declare end exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    Can someone pls direct me on how to get around this?
    If I do not handle this exception, the script fails when it attempts to update a record that does not exist and the error says : no data found exception.
    Thanks for your help.
    Edited by: user8848256 on Nov 13, 2009 6:15 PM

    No Data Found isn't an exception raised when an UPDATE cannot find any records to process.
    SQL%ROWCOUNT can be used to determine the number of rows affected by an update statement, but if 0 rows are updated then no exception will be raised (it's just not how things work).
    If you post your actual CURSOR (casualty) declaration, it's quite possible we can help you create a single SQL statement to meet your requirement (a single SQL will be faster than your current implementation).
    Have you looked in to using the MERGE command?

  • Using Sequence in FORALL Statement

    I'm using a package to get the nextval in a sequence object. Basically, it is a function that returns select user_seq.nextval from dual.
    But I get 'column not allowed here' error. PL/SQL: ORA-00984: column not allowed here
    OPEN users_ins ;
                 LOOP
                    FETCH         naf_users_ins
                    BULK COLLECT
                    INTO           arr_person_key
                                 , arr_person_id
                                 , arr_first_name
                                 , arr_middle_name
                                 , arr_last_name
                                 , arr_username
                                 , arr_user_status_seq
                                 , arr_creation_date
                                 , arr_comments
                   LIMIT         100 ;
    FORALL idx IN 1 ..  arr_person_key.COUNT
                     SAVE EXCEPTIONS
                       INSERT INTO users
                        (   user_seq
                          , person_key
                          , person_id
                          , first_name
                          , middle_name
                          , last_name
                          , username
                          , user_status_seq
                          , creation_date
                          , comments
                        VALUES  (   *pkg_admin.get_nextval*
                                  , arr_person_key(idx)
                                  , arr_person_id(idx)
                                  , arr_first_name(idx)
                                  , arr_middle_name(idx)
                                  , arr_last_name(idx)
                                  , arr_username(idx)
                                  , arr_user_status_seq(idx)
                                  , arr_creation_date(idx)
                                  , arr_comments(idx)
    EXIT WHEN users_ins%NOTFOUND ;
                 END LOOP ;
                 CLOSE users_ins;
    c/code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi,
    I've recently completed a similar task, but I declared a collection with the rowtype of the table. I also added the sequence in the query of my cursor. Take a look at the following example.
    CREATE OR REPLACE PROCEDURE Insert_OR_ExternalService
    IS
    TYPE externalService_tbl IS TABLE OF OR_ExternalService%ROWTYPE;
    externalService externalService_tbl;
    CURSOR OR_ExternalServiceCursor
    IS
    select
    SEQ_ID.NEXTVAL as "Id",
    column as "ExternalId",
    column as "ExternalSystem",
    from table1
    where ...;
    BEGIN
    OPEN OR_ExternalServiceCursor;
    LOOP
    FETCH OR_ExternalServiceCursor BULK COLLECT INTO externalService LIMIT 1000;
    FORALL i IN 1 .. externalService.count
    INSERT INTO OR_ExternalService values externalService(i);
    COMMIT;
    EXIT WHEN OR_ExternalServiceCursor%NOTFOUND;
    END LOOP;
    CLOSE OR_ExternalServiceCursor;
    END;

  • FORALL MERGE statement works in local database but not over database link

    Given "list", a collection of NUMBER's, the following FORALL ... MERGE statement should copy the appropriate data if the record specified by the list exists on both databases.
    forall i in 1..list.count
    merge into tbl@remote t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    But this does not work. No exceptions, but target table's record is unchanged and "sql%rowcount" is 0.
    If the target table is in the local database, the exact same statement works:
    forall i in 1..list.count
    merge into tbl2 t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    Does anyone have a clue why this may be a problem?
    Both databases are on Oracle 10g.
    Edited by: user652538 on 2009. 6. 12 오전 11:29
    Edited by: user652538 on 2009. 6. 12 오전 11:31
    Edited by: user652538 on 2009. 6. 12 오전 11:45

    Should throw an error in my opinion. The underlying reason for not working is basically because of
    SQL> merge into   t@remote t1
         using   (    select   sys.odcinumberlist (1) from dual) t2
            on   (1 = 1)
    when matched
    then
       update set i = 1
    Error at line 4
    ORA-22804: remote operations not permitted on object tables or user-defined type columnsSame reason as e.g.
    insert into t@remote select * from table(sys.odcinumberlist(1,2,3))doesn't work.

  • Error Message in Bulk Exception.

    Hi
    When i use a normal Exception, the SQLERRM gives me the complete error along with the column name.
    Ex :
    ORA-01400: cannot insert NULL into ("BENCHMARK"."T6"."X")
    But
    When i Use Bulk_Exception, SQLERRM does not give me the complete error along with column name.
    Ex:
    ORA-01400: cannot insert NULL into ()
    Is it that Bulk_exception error messages are less informative. These error messages, does not help me in finding out which column is violation the NOT NULL constraint and hence they actually make no sense.
    Is there any way, through which i can get the complete error message as i get in the normal exception.
    I am using 9i version.
    Regards
    Nikhil

    I couldn't find exact solution to your problem, but one idea that came to mind, is resubmit statement with problematic rows (without using bulk processing) and save error messages.
    SQL> declare
      2    bulk_errors exception;
      3    pragma exception_init ( bulk_errors, -24381 );
      4   
      5    j number;   
      6   
      7    type numbers is table of number;
      8    ids numbers;
      9  begin
    10    select case when mod(abs(dbms_random.random),3)=0 then null else 1 end id bulk collect into ids
    11      from dual
    12    connect by level < 10;
    13   
    14    forall i in ids.first .. ids.last save exceptions
    15      insert into test01 values ( ids(i) );
    16    exception when bulk_errors then
    17       for i in 1..sql%bulk_exceptions.count loop
    18         j := sql%bulk_exceptions(i).error_index;
    19         begin
    20            insert into test01 values ( ids(j) );
    21         exception when others then
    22            dbms_output.put_line( 'Row #'||j||'. '||substr(sqlerrm,1,instr(sqlerrm,chr(10))-1) );
    -- substr to get only the first line
    23         end;
    24       end loop;
    25  end;
    26  /
    Row #1. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
    Row #3. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
    Row #6. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
    Row #7. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
    Row #8. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
    Row #9. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")

  • Exception placement in anonymous block

    Hi,
    I am having difficulty trying to figure out why this exception won't work.
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> DECLARE num NUMBER;
      2  compile_rec VARCHAR2(200);
      3  v_owner VARCHAR2(50);
      4  error_24344 exception;
      5  pragma exception_init(error_24344,   -24344);
      6 
      7  BEGIN
      8 
      9     v_owner := 'FMBSITE';
    10 
    11    FOR c1 IN
    12      (SELECT object_type
    13            , object_name
    14         FROM user_objects
    15        WHERE object_name NOT LIKE 'SYS%'
    16          AND object_name NOT LIKE 'BIN%'
    17          AND object_type IN ('VIEW'
    18                             ,'PACKAGE'
    19                             ,'PROCEDURE'
    20                             ,'FUNCTION'
    21                             ,'TRIGGER'
    22                             ))
    23    LOOP
    24 
    25       compile_rec := 'ALTER ' || c1.OBJECT_TYPE || ' ' || v_owner || '.' || c1.object_name || ' COMPILE';
    26 
    27       DBMS_OUTPUT.enable(500000);
    28       DBMS_OUTPUT.PUT_LINE(compile_rec || ';');
    29                    
    30       EXECUTE IMMEDIATE (compile_rec);
    31 
    32       EXCEPTION
    33       -- Do this if the object type does not compile successfully.
    34       WHEN error_24344 THEN
    35       DBMS_OUTPUT.PUT_LINE(c1.object_name || ' success with compilation error ORA-24344.');
    36       END;
    37 
    38    END LOOP;
    39 
    40  END;
    41  /
         EXCEPTION
    ERROR at line 32:
    ORA-06550: line 32, column 6:
    PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the
    following:
    begin case declare end exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    ORA-06550: line 38, column 7:
    PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
    SQL> Thank You for any assistance
    Ben

    Here's an easy one - you have one more END than you have BEGINs.
    In other words, your LOOP contains an EXCEPTION andn an END but no matching BEGIN.
    Try this:
    23    LOOP
    24  BEGIN -- <== add this line
    25       compile_rec := 'ALTER ' || c1.OBJECT_TYPE || ' ' || v_owner || '.' || c1.object_name || ' COMPILE';
    26 
    27       DBMS_OUTPUT.enable(500000);
    28       DBMS_OUTPUT.PUT_LINE(compile_rec || ';');
    29                    
    30       EXECUTE IMMEDIATE (compile_rec);
    31 
    32       EXCEPTION
    33       -- Do this if the object type does not compile successfully.
    34       WHEN error_24344 THEN
    35       DBMS_OUTPUT.PUT_LINE(c1.object_name || ' success with compilation error ORA-24344.');
    36       END;
    37 
    38    END LOOP;

  • Exception handling in stored process, loop IF..ELSE

    Hello Guys,
    we want to put in exception handling in the loop but get the following error:
    Error(43,3): PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: begin case declare end exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
    create or replace
    PROCEDURE xxxx
    FOR MESSSY IN
    select I.*
    FROM x I
    LOOP
    IF upper(CODE)='N' THEN
    INSERT INTO T_MESS(MP)
    select I.MP_ID
    FROM T_ME
    ELSIF upper(MESSSY.k2)='L' THEN
    DELETE T_MESS WHERE T_MESS.MP = MESSSY.MP;
    END IF;
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
    A program attempted to insert duplicate values in a column that is constrained by a unique index.
    DBMS_OUTPUT.PUT_LINE ('A program attempted to insert duplicate values in a column that is constrained by a unique index.')
    --No Rollback
    END;
    COMMIT;
    END LOOP;
    END xxxx;
    does someone know why?

    BluShadow wrote:
    Well, your code is missing all sorts of bits and we don't have your data or your exact logic to know what it's supposed to be achieving.
    That is right, you dont have my data and that is why I was suprised by your comment.
    Since the input table might contain a few thousand rows and each of those might need to
    be considered N , D, or C and each case has a different handling I can not imagine how this
    can be all done with a merge statement.
    MERGE
    T_METRICPOINT_META with T_METRICSSYSTEM_LOAD where T_METRICSSYSTEM_LOAD .LOAD_DATE=to_char(sysdate)
    WHEN MATCHED THEN --we know those are the metric points that have to be loaded today, but we still need to do a IF..ELSE to handle them
    WHEN NOT MATCHED THEN -- not considered in todays load
    ----original code-----
    create or replace
    PROCEDURE myprocedure AS
    BEGIN
    --Extracting the records from T_METRICSSYSTEM_LOAD which have todays load date. Corresponding to these MP_System, we extract the MP_IDs from the T_METRICPOINT_META table.
    --Comapring these MP_IDs with the MP_IDs from the source(T_METRICPOINT_IMPORT) and extracting only those Metric points which need to be loaded today.
    FOR METRICSSYSTEM IN
    select I.*
    FROM T_METRICPOINT_IMPORT I
    where I.LOADDATE = TO_CHAR(SYSDATE) AND I.MP_ID IN
    (select a.MP_ID
    from T_METRICPOINT_META a INNER JOIN T_METRICSSYSTEM_LOAD b on a.MP_SYSTEM = b.MP_SYSTEM where b.LOAD_DATE=to_char(sysdate))
    LOOP
    --If mutation code in the source/import data is "N", the record is inserted as it is in the "T_METRICPOINTS" table.
    IF upper(METRICSSYSTEM.MUTATIONCODE)='N' THEN --new
    INSERT INTO T_METRICPOINTS(MP_ID, ......)
    SELECT DISTINCT I.MP_ID,.....
    FROM T_METRICPOINT_IMPORT I WHERE I.MP_ID = METRICSSYSTEM.MP_ID
    ELSIF upper(METRICSSYSTEM.MUTATIONCODE)='D' THEN --delete
    DELETE T_METRICPOINTS WHERE T_METRICPOINTS.MP_ID = METRICSSYSTEM.MP_ID AND T_METRICPOINTS.KEY = METRICSSYSTEM.KEY;
    ELSIF upper(METRICSSYSTEM.MUTATIONCODE)='C' THEN --correction
    UPDATE T_HISTORYMETRICPOINTS H
    SET CHANGE_DATE = to_char(sysdate)
    WHERE H.MP_ID=METRICSSYSTEM.MP_ID AND H.KEY = METRICSSYSTEM.KEY;
    INSERT INTO T_HISTORYMETRICPOINTS(MP_ID, KEY, .....)
    --The distinct here is used, to handle 2 identical records in the input table with correction value "C". This would insert into 1 record in the T_HISTORYMETRICPOINTS table without
    --violating the primary key constraint.
    select DISTINCT I.MP_ID,I.KEY, ....
    FROM T_METRICPOINT_IMPORT I WHERE I.MP_ID = METRICSSYSTEM.MP_ID
    --END IF;
    END IF;
    COMMIT;
    END LOOP;
    END myprocedure;

Maybe you are looking for