0

There are 4 tables

Table1(Column11, Column12, Column13)
Table2(Column21, Column22)
Table3(Column31, Column32,column33)
Table4(Column21, Column22)

And the following Mapping Table:

Table5(Sourcetable,Source column ,Destination table ,Destination column)

How to insert data from Table1 as source table and destination table as Table2,table3,table,4, Through Procedures?

I am using oracle 11g. Please help to achieve this!

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
  • What have you tried so far? What exactly do you want? A procedure that reads out the source table/column and destination table/column from table5 and then executes the copy? – Armunin Dec 02 '13 at 12:54

1 Answers1

0

If I understand your question, this is what you are looking for:

CREATE OR REPLACE PROCEDURE cpy_table
AS
CURSOR targ_dest_relation IS
    SELECT sourcetable, sourcecolumn, destinationtable, destinationcolumn FROM table5;

BEGIN
    FOR rec IN targ_dest_relation loop
        execute immediate 'insert into ' || rec.destinationtable || '(' || rec.destinationcolumn || ') select ' || rec.sourcecolumn || ' from ' || rec.sourcetable;
    END loop;
END;
/

SQL Fiddle

Armunin
  • 986
  • 7
  • 18