简体   繁体   English

如何将选择性数据从一个数据库复制到另一个数据库(ORACLE)

[英]How to copy selective data from one database to another (ORACLE)

We have a need to find a way to copy certain data from production into our dev regions so that we can debug/fix any issue. 我们需要找到一种方法将生产中的某些数据复制到我们的开发区域,以便我们可以调试/修复任何问题。 Sometimes single user related data gets impacted. 有时单个用户相关数据会受到影响。 We have to replicate the same scenario in dev and find a solution. 我们必须在dev中复制相同的场景并找到解决方案。 Presently we follow two approaches:- 目前我们遵循两种方法: -

 1. Check the audit history and try to recreate the similar scenario
    in  dev. <50% sucess rate in recreating the exact same scenario.
 2. Restore+Encrypt the "whole" production into dev and then continue
    on  the work. It is an overkill if issue impacts only a single user.

So I am trying to find a way to just select a single user data from production and insert it into dev region. 所以我试图找到一种方法来从生产中选择单个用户数据并将其插入到dev区域。

We just have Java and Oracle. 我们只有Java和Oracle。 Can't use any external tools. 不能使用任何外部工具。 Because we dont have license and cannot download freeware due to security issues. 因为我们没有许可证,因安全问题无法下载免费软件。

I tried the follwing:- 我尝试了以下内容: -

  1. Write a java code which will query the informaition schema tables to find the relationships between the tables and create select statements like below:- 编写一个java代码,它将查询信息模式表以查找表之间的关系并创建如下所示的select语句: -

select 'insert into TABLE1(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE1 where ID='1006' union all 
select 'insert into TABLE2(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE2 WHERE TABLE1ID in ( select ID FROM TABLE1 where ID='1006') union all 
select 'insert into TABLE3(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE3 WHERE TABLE2ID in ( select ID FROM TABLE2 WHERE TABLE1ID in ( select ID FROM TABLE1 where ID='1006'));
2. Use this set of selects in production, so that you get a set of insert statements as output. 2.在生产中使用这组选择,以便获得一组插入语句作为输出。 3. Use the insert statements in dev. 3.在dev中使用insert语句。

Problem:- The select queries are becoming huge. 问题: -选择查询变得越来越大。 Around 25 MB in total :( We cannot even execute that big query in production. 总共约25 MB :(我们甚至无法在生产中执行那个大问题。

Could you suggest any better approach for this usecase? 你能为这个用例建议更好的方法吗? Does oracle itself allow selective data exports? oracle本身是否允许选择性数据导出? Or any other way I should write my java code? 或者我应该编写我的java代码的任何其他方式?

我们使用这样的东西将记录从一个数据库移动到另一个数据库:

copy from username/password@database1 to username/password@database2 insert target_table using select * from source_table where where_clause_goes_here;

Use datapump to move data for the tables you need and with the whereclause you want. 使用数据泵移动所需表格的数据,并使用您想要的whereclause。 Straight forward and standard functionality of the database. 数据库的直接和标准功能。

If both the DBs are Oracle, you can create a DBLINK in your local database for the remote DB and Create a job in your local DB that queries all the data from remote DB using the DBLINK, and update the tables in your local database. 如果两个DB都是Oracle,则可以在本地数据库中为远程数据库创建DBLINK,并在本地数据库中创建一个使用DBLINK查询来自远程数据库的所有数据的作业,并更新本地数据库中的表。 Or there are plenty of data migration API are availabe you can give a try to one of them. 或者有大量的数据迁移API可用,你可以尝试其中一个。

Below are the some link,have a look in to them,may be it will solve your problem 下面是一些链接,看看他们,可能会解决你的问题

http://code.google.com/p/c5-db-migration/ http://code.google.com/p/c5-db-migration/

http://flywaydb.org/documentation/migration/java.html http://flywaydb.org/documentation/migration/java.html

http://migrate4j.sourceforge.net/ http://migrate4j.sourceforge.net/

http://flywaydb.org/ --- its better to use http://flywaydb.org/ ---它更好用

http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html

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

相关问题 如何以良好的性能将大量数据从一个Oracle数据库复制到另一个数据库 - How to copy huge amount of data from one Oracle database to another with good performance 使用Java将数据从一个oracle数据库表复制到另一数据库表 - Using Java Copy data from one oracle Database table to another database table 将一个人的记录从一个数据库复制到另一个数据库 - Oracle 和 Java - Copy records of a person from one database to another database - Oracle and Java 如何将表从一个数据库复制到另一个数据库? - How to copy table from one database to another? 如何将数据从一个数据库复制到另一个Oracle数据库? - How can I copy data from one DB to another oracle DB? 如何将数据列表从一个数据库复制到另一个数据库而不获取密钥为 0 1 2 3 等等 - How to copy list of data from one database to another database without getting key as 0 1 2 3 and so on 将数据从一个Oracle数据库传输到另一个数据库的最佳/最简单方法 - Best / simplest way to transfer data from one Oracle database to another 如何将数据从Oracle中的(PL /)SQL复制到另一个DBMS? - How to copy data from (PL/)SQL in Oracle to another DBMS? 如何将输入数据从一个文件复制到另一个文件? 在 java - how to copy input data from one file to another one? in java 将新记录从一个数据库复制到另一个数 - Copy new records from one database to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM