Solved

TRANSFERRING DATA BETWEEN TWO TABLES OF DIFFERENT STRUCTURE

Posted on 2010-11-26
5
449 Views
Last Modified: 2013-12-07
Hi All,

            I m trying to insert data into a table which consists of columns of different types from the table of same type.

            Can I use cursor with bulk collect option to do this?

Please help me.

Thanks & Regards,
Ravi
0
Comment
Question by:Ravi_Chintada
5 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34220836
Maybe but do you need to?

Can you not do a simple insert into tabA ( select col from tabB)?

Please post some test tables, sample data and expected results.
0
 

Author Comment

by:Ravi_Chintada
ID: 34220847
Hi
    Thanks for your response.

          Please find the following procedure that I m working around.

          Please suggest me what is the mistake in this procedure.
-----------------------------------------------------------------------------------
PROCEDURE BULK_COLLECT_INTO_MOBILE

   IS
 
  TYPE MOBILE_BULK_REC IS RECORD
       (R_MSISDN TO2_MOBILE_DETAIL.MSISDN%TYPE,
        R_ACTIVE  TO2_MOBILE_DETAIL.ACTIVE%TYPE,
        R_ICCID  TO2_MOBILE_DETAIL.ICCID%TYPE,
        R_CUSTOMER_ID TO2_MOBILE_DETAIL.CUSTOMER_ID%TYPE,
        R_IS_PREPAID  TO2_MOBILE_DETAIL.IS_PREPAID%TYPE,
        R_IMSI   TO2_MOBILE_DETAIL.IMSI%TYPE,
        R_CONTRACT_ID   TO2_MOBILE_DETAIL.CONTRACT_ID%TYPE,
      );
 
  TYPE MOBILE_BULK_TAB IS TABLE OF MOBILE_BULK_REC;    
       
  V_MOBILE_BULK      MOBILE_BULK_TAB;
  V_ARRAY_SIZE     NUMBER := 10000;
  V_TOT_CNT        NUMBER(20) :=0;
 
  CURSOR C1 IS
         SELECT
          MSISDN,
             ACTIVE,
             ICCID,
             CUSTOMER_ID,
             IS_PREPAID,
             IMSI,
             CONTRACT_ID
             
         FROM TO2_MOBILE_DETAIL_STG;
           
         
  PROCEDURE writelog(pMSG IN VARCHAR2)
  IS
    PRAGMA AUTONOMOUS_TRANSACTION;
 
  BEGIN -- writelog
    INSERT INTO POST_BULK_MOBILE_LOG
           VALUES ('BULK_COLLECT_INS_MOBILE','MAIN',pMsg, SYSDATE, 0);
    COMMIT;
  END writelog;


  BEGIN
    writelog('Started');
 
 

  OPEN C1;
  LOOP
    FETCH C1 BULK COLLECT
          INTO
              V_MOBILE_BULK LIMIT V_ARRAY_SIZE;

BEGIN
         
     INSERT INTO TO2_MOBILE_DETAIL
    (MSISDN,
             ACTIVE,
             ICCID,
             CUSTOMER_ID,
             IS_PREPAID,
             IMSI,
             CONTRACT_ID)
     SELECT    
             MSISDN,
            ACTIVE,
            ICCID,
            TO_NUMBER(CUSTOMER_ID),
            IS_PREPAID,
            IMSI,
            TO_NUMBER(CONTRACT_ID)
     FROM TO2_MOBILE_DETAIL_STG;
               
         
  EXIT WHEN V_MOBILE_BULK.COUNT=0;
     
  V_TOT_CNT:=V_TOT_CNT+V_MOBILE_BULK.COUNT;
 
  COMMIT;
 
  writelog('Inserted into MOBILE_BULK so far: '|| V_TOT_CNT);
 
  END LOOP;
 
  CLOSE C1;
 
  COMMIT;
 
  writelog('Finished - Total Rows: '|| V_TOT_CNT);
END LOOP;  

EXCEPTION
  WHEN OTHERS THEN
    writelog(SQLERRM);
END;
0
 
LVL 4

Expert Comment

by:hqassap
ID: 34221609
Please send the error message.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 34230027
I think I understand what you are trying to do.

Check out FORALL:

http://www.akadia.com/services/ora_bulk_insert.html
0
 
LVL 31

Expert Comment

by:awking00
ID: 34230086
What are the differences in structures of T02_MOBILE_DETAIL_STG and TO2_MOBILE_DETAIL?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now