[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy data from one TABLE TYPE OBJECT to another TABLE TYPE OBJECT

Posted on 2014-07-14
4
Medium Priority
?
1,223 Views
Last Modified: 2014-07-15
Hi,

CREATE OR REPLACE TYPE t1_type
    FORCE AS OBJECT
(
    code NUMBER(15),
    description VARCHAR2(15)
);

create or replace TYPE T1_TYPE_TABLE FORCE
AS
  TABLE OF T1_TYPE;

CREATE OR REPLACE TYPE t2_type
    FORCE AS OBJECT
(
    id NUMBER(15),
    name VARCHAR2(15),
    address VARCHAR2(15),
    T1_TAB  T1_TYPE_TABLE
    );
/

CREATE OR REPLACE PROCEDURE T
AS
    TYPE t2_type_a IS TABLE OF t2_type;
    TYPE t2_type_b IS TABLE OF t2_type;
BEGIN

--I want to copy value from one table object to another table object but I am getting error while doing like this
   
T2_TYPE_A := T2_TYPE_B;

T2_TYPE_A.T1_TAB := T2_TYPE_B.T1_TAB;

END;    
/

How could I copy value from one table object to another table object but I am getting error while doing as direct assignment.

Thanks and Regards,
0
Comment
Question by:Sudees
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Helena Marková earned 2000 total points
ID: 40196287
You have to change your procedure:
CREATE OR REPLACE PROCEDURE T
 AS
     TYPE t2_type_a IS TABLE OF t2_type;
     TYPE t2_type_b IS TABLE OF t2_type;
     t2_type_a1 t2_type_a;
     t2_type_b1 t2_type_b;
 BEGIN

 --I want to copy value from one table object to another table object but I am getting error while doing like this
   FOR i IN t2_type_a1.FIRST .. t2_type_a1.LAST
   LOOP
        t2_type_b1(i):=t2_type_a1(i);
   END LOOP;

 END;    
 /

Here you can find more informations about types and collections -
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_8001.htm#BABHJHEB
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/tuning.htm#BABEIACI
0
 

Author Comment

by:Sudees
ID: 40196330
Hi,

Can you help me to write any INSERT statement to move data from one TABLE OBJECT TYPE to another TABLE TYPE OBJECT

Thanks and Regards,
0
 
LVL 22

Assisted Solution

by:Helena Marková
Helena Marková earned 2000 total points
ID: 40196700
Here is something:

create or replace
PROCEDURE T1
  AS
    TYPE t1_type_a IS TABLE OF t1_type;
    t1_type_ins   t1_type_a:=t1_type_a();

    TYPE t2_type_a IS TABLE OF t2_type;
    TYPE t2_type_b IS TABLE OF t2_type;

    t2_type_a1 t2_type_a:=t2_type_a();
    t2_type_b1 t2_type_b:=t2_type_b();
 BEGIN
    t1_type_ins.EXTEND(2);
    t1_type_ins(1):=t1_type(null,null);
    t1_type_ins(1).code:=1;
    t1_type_ins(1).description:='DESC 1';
    DBMS_OUTPUT.put_line('T1_TYPE Line 1 code:'||t1_type_ins(1).code||' description:' || t1_type_ins(1).description);          

    t1_type_ins(2):=t1_type(null,null);
    t1_type_ins(2).code:=2;
    t1_type_ins(2).description:='DESC 2';
    DBMS_OUTPUT.put_line('T1_TYPE Line 2 code:'||t1_type_ins(2).code||' description:' || t1_type_ins(2).description);                    

    t2_type_a1.EXTEND(2);
    t2_type_a1(1):=t2_type(null,null,null,t1_type_table(null,null));

    t2_type_a1(1).id:=1;
    t2_type_a1(1).name:= 'Hela';
    t2_type_a1(1).address:='My Town';
    DBMS_OUTPUT.put_line('T2_TYPE Line 1 id:'||t2_type_a1(1).id||' name:' || t2_type_a1(1).name||' address:' || t2_type_a1(1).address);          

    t2_type_a1(2):=t2_type(null,null,null,t1_type_table(null,null));
    t2_type_a1(2).id:=2;
    t2_type_a1(2).name:= 'Anna';
    t2_type_a1(2).address:='Your Town';
    DBMS_OUTPUT.put_line('T2_TYPE Line 2 id:'||t2_type_a1(2).id||' name:' || t2_type_a1(2).name||' address:' || t2_type_a1(2).address);              

    t2_type_b1.EXTEND(2);          
    FOR i IN t2_type_a1.FIRST .. t2_type_a1.LAST
    LOOP
         t2_type_b1(i):=t2_type_a1(i);
         DBMS_OUTPUT.put_line('Copy of T2_TYPE Line '||i||' id:'||t2_type_b1(i).id||' name:' || t2_type_b1(i).name||' address:' || t2_type_b1(i).address);              
    END LOOP;

  END;
0
 

Author Closing Comment

by:Sudees
ID: 40198444
Thanks for your effort.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

830 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