I have table X
from remote Oracle DB A
, and table Y
in local Oracle DB B
.
The data in Y
is a partial copy of the data in X
(X
has some columns that aren't needed in Y
; the columns I need in Y
have the same names in both tables).
I periodically need to synchronize the data Y
with what's in X
(this is unidirectional – there's nothing in Y
that needs to be copied back to X
). Y
has constraints that prevent simply dropping all the data in Y
and repopulating it; I need to update what's already in 'Y', and insert any new rows from X
that don't already exist in Y
.
I've looked at a couple of options that won't work:
- The copy feature in SQL Developer would copy
X
into a brand new table, not intoY
- The export option would insert everything as new records, not update existing rows
What's the best way to do this?
Best Answer
I did it by: creating dblink from db A to DB B and using : merge into Y y using select X.columns from X@dblink x on (x.idX=y.idY) when matched then update set y.columns=x.columns --here ids are not included when not matched then insert (y.columns) values(x.columns) --ids are included x.colums and y.colums mean shared columns