Oracle. How to exp/imp data from one DB to another which already has data?

151 Views Asked by At

I have one Oracle DB with ~40 tables. Some of them have IDs = 1, 2, 3, 4, 5... and constraints.

Now I want to "copy" this data from all tables to another Oracle DB which already has the same tables.

The problem is that another DB also has records (can be the same IDs = 1, 2, 3, 77, 88...) and I don't want to lose them.

Is there some automated way to copy data from one table to another with IDs shifting and constraints?

1, 2, 3, 77, 88 +
**1, 2, 3, 4, 5**

=

1, 2, 3, 77, 88, **89, 90, 91, 92, 93**

Or I need to do it by myself?

insert into new.table
select new.sequence_id.nextval, t.* from old.table t

save new.id - old.id mapping and etc etc etc for all 40 tables?

2

There are 2 best solutions below

1
On BEST ANSWER

That's a bit dirty solution but if all IDs are numeric you can first update old IDs to negative number ID = -1 * ID (or just do it in select statement on the fly) then do insert. In that case you have all your IDs consistent, constraints are valid and they can live together with new data.

0
On

Firs, you need expdp, is second you ned remap schema new schema name in impdp