Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bulk Insert and Update issue

user11289444Dec 21 2010 — edited Dec 22 2010
Appreciate if some one can pls. look into this issue with Bulk Insert and Update


Bulk insert problem --this works if i use cursor as select d.* from detail_tab d in the below example,
but if i select specific columns it is not working
 declare
 CURSOR ins_err_det
       IS
 select d.*
          /*SELECT d.DTID_SEQ ,
  d.EMPNUM  ,
  d.projectname ,
  d.TASK ,
  d.EXP_TYPE   */
           from detail_tab d;
  TYPE id_tab_det_1 IS TABLE OF detail_tab%ROWTYPE
          INDEX BY PLS_INTEGER;
   t_id_det_1       id_tab_det_1;
   BEGIN
     BEGIN
       OPEN ins_err_det;
       FETCH ins_err_det
           BULK COLLECT INTO t_id_det_1 ;
       CLOSE ins_err_det;
       FORALL indx IN t_id_det_1.FIRST  .. t_id_det_1.LAST
               INSERT INTO a1 VALUES t_id_det_1(indx);
      EXCEPTION
             WHEN OTHERS
             THEN
                fnd_file.put_line (fnd_file.LOG, 'exception in err insert' || SQLCODE ||' ' ||SQLERRM);
                ROLLBACK;
                RETURN;
      END;
       COMMIT;
    EXCEPTION
       WHEN OTHERS
       THEN
          fnd_file.put_line (fnd_file.LOG, 'exception in CUR_INS_ERR' || SQLCODE ||' ' ||SQLERRM);
    END;
/


I am getting error PLS-00394: wrong number of values in the INTO list of a FETCH statement if i use the cursor as 


SELECT d.DTID_SEQ ,
  d.EMPNUM  ,
  d.projectname ,
  d.TASK ,
  d.EXP_TYPE   


but the given cursor works..if i select all columns with the above pl/sql but below is the  
same with cursor for loops with out bulk, can some one please look 
what is wrong with insert if is use the cursor with specific columns and insert.

Basically my table structure of  detail tab and a1 are same.


declare
CURSOR ins_err_det
      IS
         SELECT d.DTID_SEQ ,             
 d.EMPNUM  ,                  
 d.projectname ,               
 d.TASK ,                  
 d.EXP_TYPE       
          from detail_tab d;
  BEGIN
      fnd_file.put_line (fnd_file.LOG, 'inserting to err detail');
      FOR c_ins_e_rec IN ins_err_det
      LOOP
         BEGIN
            INSERT INTO a1
                        (DTID_SEQ, 
                         EMPNUM, 
                         projectname,
                         task, EXP_TYPE
                                           )
                 VALUES (c_ins_e_rec.DTID_SEQ, 
                         c_ins_e_rec.EMPNUM, 
                        c_ins_e_rec.projectname,
                         c_ins_e_rec.task, 
                         c_ins_e_rec.EXP_TYPE 
                        );
         EXCEPTION
            WHEN OTHERS
            THEN
               fnd_file.put_line (fnd_file.LOG, 'exception in err insert' || SQLCODE ||' ' ||SQLERRM);
               ROLLBACK;
               RETURN;
         END;
      END LOOP;
      COMMIT;
   EXCEPTION
      WHEN OTHERS
      THEN
         fnd_file.put_line (fnd_file.LOG, 'exception in CUR_INS_ERR' || SQLCODE ||' ' ||SQLERRM);
   END;
/






Update problem, what is wrong with the below block




declare
cursor c1
  IS
      SELECT  O.TXNDATE
        FROM FO_TRXN_STAGE_sTG g, TEST o
       WHERE g.TRXN_INTRL_ID = o.TXNID 
       AND  G.trxn_type1_cd ='2201'
-- Primary key
      ;
 
   TYPE new_data_type IS TABLE OF C1%ROWTYPE;
     
 
   new_data_tab   new_data_type;

BEGIN
   OPEN C1;
 
   LOOP
      FETCH C1
      BULK COLLECT INTO new_data_tab ;
 
     
      FORALL i IN new_data_tab.FIRST .. new_data_tab.LAST 
         UPDATE FO_TRXN_STAGE
            SET TRXN_EXCTN_DT = new_data_tab.TXNDATE(I);
       
 
      EXIT WHEN C1%NOTFOUND;
   END LOOP;
 

 
   CLOSE C1;
END; 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2011
Added on Dec 21 2010
11 comments
985 views