你好,游客 登录 注册 搜索
背景:
阅读新闻

以交互方式使用exp/imp的演示

[日期:2014-11-21] 来源:Linux社区  作者:aaron8219 [字体:大 中 小]
二、多表导出导入测试
 
--导出2个测试表(t1,t2)到同一个dmp文件中
SQL> !
[Oracle@ora10g ~]$ exp
 
Export: Release 10.2.0.1.0 - Production on 11 11:08:38 2014
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
 
Username: zlm
Password: 
 
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 > 8192
 
Export file: expdat.dmp > t1_t2.dmp
 
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > t
 
Export table data (yes/no): yes > 
 
Compress extents (yes/no): yes > 
 
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
 
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > t1
 
. . exporting table                             T1     100710 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > t2
 
. . exporting table                             T2          2 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >     --指定完所需导出的表后回车退出
 
Export terminated successfully without warnings.
[oracle@ora10g ~]$ exit
exit
 
--删除源表
SQL> drop table t1 purge;
 
Table dropped.
 
SQL> drop table t2 purge;
 
Table dropped.
 
--执行导入
SQL> !
[oracle@ora10g ~]$ imp
 
Import: Release 10.2.0.1.0 - Production on 11 11:09:38 2014
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
Username: zlm
Password: 
 
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
 
Import file: expdat.dmp > t1_t2.dmp
 
Enter insert buffer size (minimum is 8192) 30720> 
 
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no > 
 
Ignore create error due to object existence (yes/no): no > 
 
Import grants (yes/no): yes > 
 
Import table data (yes/no): yes > 
 
Import entire export file (yes/no): no >     --有别于第一个单表导入的测试,这里如果选择了no,那么就可以分别指定需要导入的部分(t1_t2.dmp中含有t1,t2两个表的逻辑语句,但是现在只导入t1)
Username: zlm
 
Enter table(T) or partition(T:P) names. Null list means all tables for user    --如果直接回车,就表示导入全部表
Enter table(T) or partition(T:P) name or . if done: t1
 
Enter table(T) or partition(T:P) name or . if done: .    --只导入t1表,用“.”退出,注意,不是回车了
 
. importing ZLM's objects into ZLM
. importing ZLM's objects into ZLM
. . importing table                           "T1"     100710 rows imported
Import terminated successfully without warnings.
[oracle@ora10g ~]$ exit
exit
 
SQL> select count(*) from t1;
 
  COUNT(*)
----------
    100710
 
SQL> select count(*) from t2;
select count(*) from t2
                     *
ERROR at line 1:
ORA-00942: table or view does not exist
 
可以看到,只有t1表是导入的,虽然之前导出的是t1,t2两张表到一个dmp文件,但是导入的时候,可以只按照需要的内容单独导入,相当于取了一个子集
 
SQL> !
[oracle@ora10g ~]$ imp
 
Import: Release 10.2.0.1.0 - Production on 11 11:10:48 2014
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
Username: zlm
Password: 
 
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
 
Import file: expdat.dmp > t1_t2.dmp
 
Enter insert buffer size (minimum is 8192) 30720> 
 
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no > 
 
Ignore create error due to object existence (yes/no): no > yes
 
Import grants (yes/no): yes > 
 
Import table data (yes/no): yes > 
 
Import entire export file (yes/no): no > yes
 
. importing ZLM's objects into ZLM
. importing ZLM's objects into ZLM
. . importing table                           "T1"     100710 rows imported
. . importing table                           "T2"          2 rows imported
Import terminated successfully without warnings.
 
这次直接选择了把整个导出文件的内容到导入到zlm用户,注意后面选项的不同之处
 
[oracle@ora10g ~]$ exit
exit
 
SQL> select count(*) from t1;
 
  COUNT(*)
----------
    201420
 
SQL> select count(*) from t2;
 
  COUNT(*)
----------
         2
 
现在t1,t2表都有数据了,不同的是,由于刚才用了ingore error的方式把t1表导出了2次,所以t1表中成了20W行
linux
相关资讯       EXP/IMP 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款