Stored procedure for copying data from one table to another

I have pairs of tables in the format TABLE and TABLE_TWIN now

  • TABLE is the main table with a lot of data.
  • TABLE_TWIN - table with the same fields with small data (different data)

Now I would like to copy all rows from TABLE_TWIN to TABLE using a stored procedure. I have many such tables, and I would like the stored procedure to take the name of the table as parameter (s) so that I can use the same procedure for each pair of tables. I do not want to write long INSERT because these tables have about 50 attributes each.

I am not good at PL / SQL, so I need help here.

Thanks!

+4
source share
2 answers

SQL is not so long ... But if you prefer a procedure, here it is:

 create or replace procedure table_copy( p_tab_from varchar2, p_tab_to varchar2) is begin execute immediate 'insert into '||p_tab_to||' (select * from '||p_tab_from||')'; end; 
+8
source
 insert into table_twin (select * from table) 

gotta do it

+5
source

All Articles