有谁有示例数据迁移脚本(Oracle 10g 到 Oracle 10g,但架构不同)?
我正在尝试编写一个数据迁移 pl/sql 脚本,以将一个模式中的某些数据传输到另一台服务器上的不同模式。第二个数据库最初是原始数据库的子集,但我们修改了架构。因此,我不能只对每个表使用以下内容:
Insert into DB2.table_name select * from DB1.table_name2;
我尝试搜索示例脚本来显示如何执行此操作,但找不到任何内容。
I am trying to write a data migration pl/sql script to transfer some of the data in one schema to a different schema on another server. The second database started as a subset of the original database, but we have modified the schema. So I can't just use the following for each table:
Insert into DB2.table_name select * from DB1.table_name2;
I have tried doing a search for sample scripts that show how to do this, but couldn't find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果 DB1.table_name 和 DB2.table_name 之间的列不同,那么您必须在插入语句中指定列列表。不幸的是,这里并没有真正的“灵丹妙药”。
话虽如此,为了加快该过程,您可以编写一些 PL/SQL 来生成插入语句,然后您可以手动修复这些语句。下面是执行此操作的示例 PL/SQL 代码。在此示例中,l_src_table 将是您的源表,l_target_table 将是您的目标表。显然,您仍然需要手动修复此代码生成的 SQL 语句,但这至少会生成一个模板 SQL,这将为您节省大量时间。
If the columns are different between DB1.table_name and DB2.table_name then you're going to have to specify a column list in the insert statement. Unfortunately, there's not really a "magic bullet" here.
With that said, to speed up the process you could write some PL/SQL to generate the insert statements, and then you could fix those by hand. Here's a sample PL/SQL code to do this. In this example, l_src_table would be your source table and l_target_table would be your target table. Obviously, you'll still have to manually fix the SQL statement this code generates, but this will at least generate a template SQL which should save you a lot of time.
您可以创建数据库链接。
然后,如果您尝试从 db1 迁移到 db2:
选择可以根据需要复杂或简单。
You can create a database link.
Then, if you're trying to migrate from db1 to db2:
The select can be as complex or simple as needed.
如果您需要经常这样做,那么另一个选择是使用模式同步工具。 Toad、dbsolo 以及可能其他一些工具都可以使用。它节省了我很多时间和精力。
If you need to do this often enough,then another option is to use a schema synchronization tool. Toad, dbsolo and probably a few other tools can be used. It has saved me a lot of time and effort.
可能有多种情况。当源表和目标表相同时,脚本如下所示。
但是,常见的情况是有多个源和一个目标。那么解决方案如下所示
另外,检查合并查询以获得更好的结果更新时
There can be multiple cases. When source and destination table are same the script is like this
However, the common scenario is that there will be multiple sources and one destination. Then the solution is like below
Also, check the Merge query for better results while updating