Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the columns are different between DB1.table_name and DB2.table_name then you're going to have to specify a column list in the insert statement. Unfortunately, there's not really a "magic bullet" here.</p> <p>With that said, to speed up the process you could write some PL/SQL to generate the insert statements, and then you could fix those by hand. Here's a sample PL/SQL code to do this. In this example, l_src_table would be your source table and l_target_table would be your target table. Obviously, you'll still have to manually fix the SQL statement this code generates, but this will at least generate a template SQL which should save you a lot of time.</p> <pre><code>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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload