• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 709
  • Last Modified:

how to load data into a table across different databases

I have two same structured tables in two different schemas in two different databases in different networks, environments. Say one is table is in testing environment other table is development environment. What is the easiest way to load the changes that made in testing environment table to the development environment table. Any ideas, sample code, resources, links highly appreciated. Thanks in advance
  • 3
  • 2
  • 2
  • +1
3 Solutions
dbms_datapump  is quite easy...

here's a basic framework to move schemas...

for more information check...

   v_handle NUMBER;
   DBMS_DATAPUMP.OPEN (operation   => 'IMPORT',
                       job_mode    => 'SCHEMA',
                       remote_link => 'source_db_name'
--  put the schemas in quotes
   DBMS_DATAPUMP.metadata_filter (handle => v_handle,
                                  NAME   => 'SCHEMA_LIST',
                                  VALUE  => '''SCHEMA1'',''SCHEMA2'''
--  options are TRUNCATE, REPLACE, APPEND, and SKIP. 
   DBMS_DATAPUMP.set_parameter (handle => v_handle,
                                NAME   => 'TABLE_EXISTS_ACTION',
                                VALUE  => 'REPLACE'
--  remove this line if you want the data as well
--  don't change the value, remove the call entirely
   DBMS_DATAPUMP.DATA_FILTER(handle  => v_handle,
                             NAME    => 'INCLUDE_ROWS',
                             VALUE   => 0
   dbms_datapump.add_file(handle => v_handle,
                          filename => 'you_log_file_name_here.log',
                          directory => 'DATA_PUMP_DIR',
   DBMS_DATAPUMP.set_parallel(v_handle, 4);
   DBMS_DATAPUMP.start_job (v_handle);

Open in new window

Create a database link on one of the databases and then use this database link to retrieve the data from the other database.

For example, you have database Dev and database Test.  Assuming your data has already been setup on Dev, then on the Test database create a database link:

create public database link devdb
connect to dev_user
identified by "dev_user_password"
using 'XXX';

dev_user is the Oracle account of the owner of the table on your dev database and dev_user_password is the password for this account.  XXX is the entry in your tnsnames.ora file that identifies the Dev database.

The database link can then be used on the Test system in a sql statement to access data on the Dev database as follows:

insert into my_table_on_test
select * from my_table_on_dev@devdb;

This statement assumes that my_table_on_test and my_table_on_dev have exactly the same structure.
gudii9Author Commented:
problem is we do not have whole lot of privileges like DBA etc on many databases. Any other quick easy way without hasle of privileges etc. Please advise
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

johnsoneSenior Oracle DBACommented:
Dump to a text file and load using SQL*Loader.

The dump would look something like this:

set lines 20000 pages 0 term off echo off feedback off trimspool on
spool output.txt
select field1 || chr(9) || field2 || chr(9) || ...
from table;
spool off

Then the SQL*Load control file would look something like this (in place of <tab> you need an actual tab character).  This will truncate the existing table and reload it from the text file.

INFILE 'output.txt'
trailing NULLCOLS
( field1,
  .... )
do you have the same user and password on both the target and source?

if so,  you don't need to create a link explicitly.  you can do the inserts as Milleniumaire showed above but where you have the dblink name you instead just use the tnsconnect string.

insert into my_table_on_test
select * from my_table_on_dev@XXX;

note, this ONLY works if the user you are running the insert also exists on the source system with the same password
johnsoneSenior Oracle DBACommented:
There is also the copy command in SQL*Plus.
You could use export and import.  These operating system commands allow you to export data from a table, schema or database into a file and then import that data into another database.

On your dev system at the os command line (assuming you are using unix) type:


then enter the username password of the user owning the tables.  Follow the prompts to export a single table.  You will then have a file with a .dmp extension.  Copy this binary file to the machine on which the test database resides and at the os prompt type:


again, follow the prompts and the data in the .dmp file will be loaded into the relevant tables.

Be aware that the data will be appended to any other data that already exists in the tables.  Ideally, the schema owners (Oracle accounts) should be the same on dev and test to avoid requiring special privileges.

If you have access to a development tool called Toad it is also possible to create "insert" scripts from table data, which you can then run against another database.  To do this, right click on a table and chose Export Data.
gudii9Author Commented:
thank you
glad we could help
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.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now