简体   繁体   English

在Oracle中将数据从一个数据库复制到另一个数

[英]Copy data from one database to another in Oracle

I have 2 Oracle databases and I frequently copy data from prod DB to test DB using TOAD, by generating insert scripts for Prod DB and running it on the test DB later. 我有2个Oracle数据库,我经常使用TOAD将数据从prod DB复制到测试数据库,方法是为Prod DB生成插入脚本,然后在测试数据库上运行它。

I am trying to do it faster through a batch file. 我试图通过批处理文件更快地完成它。

I think that I can use this solution but the DB has an auto-increment column. 我认为我可以使用解决方案,但DB有一个auto-increment列。 If I use this solution, would that column be affected? 如果我使用此解决方案,该列是否会受到影响? Do I need to change the script in some way? 我需要以某种方式更改脚本吗? I haven't tried this so far as I have no access do the DB and would be able to test this only on Monday. 我没有尝试这个,因为我没有访问数据库,只能在星期一测试。

Is there a better way I can accomplish this? 有没有更好的方法来实现这一目标? What I am essentially looking for is doing the whole copy procedure using a batch file, which would minimize the time I spend doing this using TOAD. 我基本上寻找的是使用批处理文件执行整个复制过程,这将最大限度地减少我使用TOAD执行此操作所花费的时间。

Also, it's fine by me if I can be guided in the right direction, if solution is not simple. 此外,如果我能在正确的方向上指导,如果解决方案不简单,我也没关系。

Make sure the two tables have the same structure. 确保两个表具有相同的结构。

Connect to the target database. 连接到目标数据库。

Create a public link to the source database. 创建指向源数据库的公共链接。 The user should have "CREATE PUBLIC DATABASE LINK" system privilege to do this. 用户应具有“CREATE PUBLIC DATABASE LINK”系统特权来执行此操作。

CREATE PUBLIC DATABASE LINK mylink
  CONNECT TO source_user IDENTIFIED BY source_password
  USING 'source_entry_in_tnsnames';

Copy the data: 复制数据:

INSERT INTO mytable SELECT * FROM mytable@mylink;

If the primary key of the table comes from a sequence, set the sequence to - at least - the same value as in the source database: 如果表的主键来自序列,请将序列设置为 - 至少 - 与源数据库中的值相同:

ALTER SEQUENCE mysequence increment by 100000;
SELECT mysequence.nextval FROM DUAL;
ALTER SEQUENCE mysequence increment by 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM