Export and Import Table Data

本文介绍使用Oracle内置工具exp/imp进行数据库迁移的方法。通过实际案例展示如何从开发环境DBDEV迁移到测试环境DBSTAGE的具体步骤,包括导出数据、处理约束及索引等关键环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Many options are available for a scenario when we need to transferring or migrating data across two different Oracle database. One option is using Oracle built-in application exp and imp. exp is used to extract data and other schema objects into a dump file, and imp is the one who can read that file and import it to another machine.

Why using exp/imp? One reason is because it’s speed. From my own experience, migrating 3000 rows data can take significant amount of time if using manual insert with SQL statement, while migrating 60000 rows data using exp/imp would take no more than few minutes.

What will you need? A machine with Oracle Database installation, configured properly, a TNS record for both machine you wish to migrate, and enough disk space for storing dump file, depending on how much your data.

Let’s say we need to migrate data on app1 schema from a development machine DBDEV to staging machine DBSTAGE. The tables need to be migrated are PORT and CARD tables. DBSTAGE already has the tables created, all it need is the data from DBDEV.

First we will need to export the data. Syntax for exporting table is like this:

1
exp username/password @database tables=table1,table2file=table_data.dmp

If you don’t wish to include the password on command line, you can use this format instead:

1
exp username @database tables=table1,table2file=table_data.dmp

The password will be prompted when the command executed. If we put the above scenario the final command will look like this:

1
exp app1/password@DBDEV tables=PORT,CARDfile=table_data.dmp

Executing this command will present you with export status screen, will inform how much data exported and if the command exited with or without warning, or even with error. After you got your command prompt back you should be seeing one file named table_data.dmp. Next action we will be using this file to import to DBSTAGE machine.

Syntax for using imp is no different than exp:

1
imp username/password@databasefile=table_data.dmp

According to the scenario we should use this command:

1
imp app1/password@DBSTAGEfile=table_data.dmp ignore=y

Notice now we using DBSTAGE connection instead DBDEV, and also using optionignore=y. Why using this option? Since on DBSTAGE the tables has already been created, we should use this option to prevent the command for being stopped because the object already exist on target database. If we not including this option, the command will be stopped with error because it failed to create the table, which is already exist.

Executing the above command will present you with similar status screen with exp one, telling you how much rows data has been imported.

Some additional information:

  • If you hit with error about constraint, like ORA-02291: integrity constraint, make sure data referenced by the constraint has also been imported. You can also try to turn off the specified constraint before importing.
  • If you migrating a considerably huge amount of data, it may be wise to prevent the index from being exported with option indexes=no (while exporting). You can rebuild the index after the import complete.

Reference:

http://www.orafaq.com/wiki/Import_Export_FAQ

转载于:https://my.oschina.net/u/138995/blog/212758

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值