使用C#将数据从一个oracle数据库复制到另一个oracle数据库
将数据从一个 Oracle 数据库复制到另一个 Oracle 数据库的标准方法是什么?
1)从源表读取数据并使用配置复制到目标上的临时表(即有超过1个表,每个表都有单独的临时表) 2)现在没有clob数据,但将来可能会使用clob数据。 3)将所有内容读取到内存(如果以块的形式读取大数据)
不应该使用Oracle链接 不应该使用文件 代码应该仅使用 C#,而不是任何数据库过程。
What is the standard way of copying data from one oracle database to another.
1) Read data from source table and copy to temp table on destination using configuration( i.e. there are more than 1 table and each table has separate temp table)
2) Right now there is no clob data, but in future clob data might be used.
3) Read everything to memory(if large data read in chunks)
Should not use Oracle links
Should not use files
Code should be only using C# but not any database procedures.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用来执行此操作的一种方法是在源数据库上使用 DataReader 并仅在目标数据库上执行插入(使用 绑定参数 当然)。
请注意,DataReader 非常擅长在表中移动时不使用太多内存(我相信默认情况下它使用快进、只读游标)。这意味着在给定时间内存中仅保存少量数据。
以下是需要注意的事项:
关系
如果您正在处理具有关系的数据,则需要处理它。我见过两种方法来处理这个问题:
自动生成的 ID 值
通常通过禁用给定表的自动增量功能并允许身份插入(我使用一些 SQL Server 术语,我不记得它在 Oracle 上如何工作)。
交易
如果您要移动大量数据,交易的成本将会很高。
可重复性/删除目标数据
除非您比我们其他人更出色,否则您可能需要多次运行这个东西(至少在开发期间)。这意味着您可能需要一种删除目标数据的方法。
特定于平台的方法
在 SQL Server 中,有多种方法可以极快地执行批量插入(通过放弃引用完整性检查等小事情)。 Oracle 工具集中可能有类似的功能。
表/列元数据
我还没有在 Oracle 中执行此操作,但看起来您可以使用提到的视图来获取表和列的元数据oracle.com/docs/cd/B28359_01/server.111/b28310/tables014.htm" rel="nofollow">此处。
One way that I've used to do this is to use a DataReader on the source database and just perform inserts on the target database (using Bind Parameters for sure).
Note that the DataReader is excellent at not using much memory as it moves through a table (I believe that by default it uses a Fast Forward, Read Only cursor). This means that only a small amount of data is held in memory at a given time.
Here are the things to watch out for:
Relationships
If you're working with data that has relationships, you're going to need to deal with that. There are two ways that I've seen to deal with this:
Auto Generated Id Values
These columns are usually handled by disabling the auto increment functionality for the given table and allowing identity insert (I'm using some SQL Server terms, I can't remember how it works on Oracle).
Transactions
If you're moving a lot of data, transactions will be expensive.
Repeatability / Deleting Target Data
Unless you're way more awesome than the rest of us, you'll probably have to run this thing more than once (at least during development). That means you might want a way to delete the target data.
Platform Specific Methods
In SQL Server, there are ways to perform bulk inserts that are blazingly fast (by giving up little things like referential integrity checking). There might be a similar feature within the Oracle toolset.
Table / Column Metadata
I haven't had to do this in Oracle yet, but it looks like you can get metadata on tables and columns using the views mentioned here.