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

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,
SudeesSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Helena Markováprogrammer-analystCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SudeesSoftware DeveloperAuthor Commented:
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
Helena Markováprogrammer-analystCommented:
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
SudeesSoftware DeveloperAuthor Commented:
Thanks for your effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.