If the columns differ between DB1.table_name and DB2.table_name, then you will need to list the columns in the insert statement. Unfortunately, there is no "magic bullet".
With that said, to speed up the process, you can write PL / SQL to generate insert statements, and then you can fix them manually. Here is a sample PL / SQL code for this. In this example, l_src_table will be your source table, and l_target_table will be your target table. Obviously, you still have to manually fix the SQL statement generated by this code, but this will at least lead to the creation of an SQL template that should save you a lot of time.
DECLARE l_insert_stmt VARCHAR2(4000); l_comma VARCHAR2(1) DEFAULT ' '; l_src_table VARCHAR2(500) := 'TABLE1'; l_src_table_owner VARCHAR2(500) := 'DB1'; l_target_table VARCHAR2(500) := 'TABLE2'; l_target_table_owner VARCHAR2(500) := 'DB2'; BEGIN l_insert_stmt := 'INSERT INTO ' || l_target_table || ' ( '; FOR rec IN (SELECT column_name FROM all_tab_columns WHERE TABLE_name = l_target_table AND owner = l_target_table_owner) LOOP l_insert_stmt := l_insert_stmt || l_comma || rec.column_name; l_comma := ','; END LOOP; l_insert_stmt := l_insert_stmt || ' ) '; l_insert_stmt := l_insert_stmt || ' SELECT '; l_comma := ' '; FOR rec IN (SELECT column_name FROM all_tab_columns WHERE TABLE_name = l_src_table AND owner = l_src_table_owner) LOOP l_insert_stmt := l_insert_stmt || l_comma || rec.column_name; l_comma := ','; END LOOP; l_insert_stmt := l_insert_stmt || ' FROM ' || l_src_table; dbms_output.put_line(l_insert_stmt); END;
source share