oracle導出表的辦法

1.先進行表分析(一定要執行此步,否則查詢空表可能不準確)

select 'analyze table '||table_name||' compute statistics;' from user_tables;

2.再查詢哪些表是空的(此步可以省略,直接進行第三步)

select table_name from user_tables where NUM_ROWS=0 order by table_name;

3.最後生成alert語句
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 order by table_name;

4.導出表---通過PLSQL Developer(tools->Export Tables)導出。

5.導入時通過命令行(cmd)進行導入 imp user/pass@orcl file=E:\data\data.dmp full=y

6.導出序列和視圖 ---通過PLSQL Developer(tools->Export User Objects,然後選擇要導出的視圖)導出。

7.導入序列和視圖---將seq.sql和view.sql中的空間名替換掉,然後新建Command Window-->分別load兩個文件導入執行即可。

 

*********************************另外一種導出方法*********************************

EXP和IMP是客戶端工具程序,它們既可以在客戶端使用,也可以在服務端使用。

EXPDP和IMPDP是服務端的工具程序,他們只能在ORACLE服務端使用,不能在客戶端使用。

如果想導入的用戶已經存在:
1. 導出用戶 expdp user1/pass1 directory=dumpdir dumpfile=user1.dmp
2. 導入用戶 impdp user2/pass2 directory=dumpdir dumpfile=user1.dmp REMAP_SCHEMA=user1:user2 EXCLUDE=USER

如果想導入的用戶不存在:
1. 導出用戶 expdp user1/pass1 directory=dumpdir dumpfile=user1.dmp
2. 導入用戶 impdp system/passsystem directory=dumpdir dumpfile=user1.dmp REMAP_SCHEMA=user1:user2
3. user2會自動建立,其權限和使用的表空間與user1相同,但此時用user2無法登錄,必須修改user2的密碼

 

今天需要另一個數據庫的用戶表導入到當前庫中,但用戶名不相同,以前exp/imp時,可以指定fromuser和touser來解決,在expdp中也提供了類似的解決方法

impdp system/zlsoft dumpfile=expdp:EXPDP_ZLHIS.DMP nologfile=y tables=zlhis.dept remap_schema=zlhis:scott remap_tablespace=ZL9BASEITEM:users,zl9indexhis
:users,zl9indexmtl:users table_exists_action=truncate exclude=object_grant

幾個重要參數的說明一下:

1、remap_user 重新映射用戶,格式: source_user1:target_user1,source_user2:target_user2

2、remap_tablespace 重新映射表空間

3、 table_exists_action 表已經存在的動作 有效關鍵字: (SKIP), APPEND, REPLACE 和 TRUNCATE。

4、exclude=object_grant 跳過對象授權

 

****************第三種導出方法(常用)****************

exp scott/tiger@orcl file=D:\database.dmp

imp scott/tiger@orcl full=y file=D:\database.dmp

 

非本機:

imp user1/[email protected]:1521/orcl file=E:\data.dmp full=y

exp user1/[email protected]:1521/orcl file=E:\data.dmp full=y

 

參看:https://blog.csdn.net/mzd8341/article/details/76595772

 這樣導出的表可能不全,請先看文章開頭如何執行 alter table table_name_xxx allocate extent;

 

*********************************導出部分表方法*********************************

exp scott/tiger@orcl  file=d:\test.dmp statistics=none TABLES=(TABLE1,TABLE2,TABLE3)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章