Reputation: 560
I have local and remote database. The local database is a replica of remote database. I have to insert new records from remote database into local database. There are 14 tables in remote database, so i need to track changes in all 14 tables.
I know I can select every table in remote database and check if record exists in local database if not then insert it.
Is there another way to do it? In java maybe? What approach would be the best?
Upvotes: 1
Views: 540
Reputation: 4818
Let's start with DBlink to remote DB
CREATE PUBLIC DATABASE LINK REMO
CONNECT TO <user_name>
IDENTIFIED BY <password>
USING '<service_name>';
then insert with loop over all tables from user schema. Or if you want insert only some tables please define proper condition for those 14 tables.
begin
for x in (select table_name from user_tables) loop
execute immediate 'insert into ' || x.table_name || ' (select * from ' || x.table_name || '@REMO minus select * from ' || x.table_name || ')';
commit;
end loop;
end;
/
This will insert only new records (in fact records that exists (or were changed) on remote and not exists on local). If taht's what you need this will work. If you need synchronisation this is not the solution.
Upvotes: 2
Reputation: 4120
if you have only one local database and it runs all the time - you can use triggers from remote db to insert to the local db.
BTW: Go from local to check remote manually is not a good idea. What if existing remote record changed, but local still have old values?
Also there bunch of Oracle tools to make replications and synchronizations between databases. It is best to dig in it.
Upvotes: 1