ตัวอย่างด้านล่างเอามาจาก oracleinth
1 การ Export/Import แบบเจาะจงตาราง
expdp user/password@SID tables=table_name directory=_directory_ dumpfile=filename.dmp logfile=logname.log
impdp user/password@SID tables=table_name directory=_directory_ dumpfile=filename.dmp logfile=logname.log
2 การ Export/Import แบบเจาะจง Schema
expdp user/password@SID schemas=schema_name directory=_directory_ dumpfile=filename.dmp logfile=logname.log
impdp user/password@SID schemas=schema_name directory=_directory_ dumpfile=filename.dmp logfile=logname.log
3 การ Export/Import แบบทั้ง Database (แบบ Full)
User ที่จะทำการ Export/Import แบบ Full ได้นั้นจะต้องเป็น User ที่มีสิทธิ์ในการ Export/Import Full Database เท่านั้น ในที่นี้ยกตัวอย่างเป็น User: Sys Password: manager1 และพารามิเตอร์ full จะเป็นตัวบอกว่าจะทำการ Export/Import แบบ Full
expdp sys/manager1@SID full=Y directory=_directory_ dumpfile=filename.dmp logfile=logname.log
impdp sys/manager1@SID full=Y directory=_directory_ dumpfile=filename.dmp logfile=logname.log
โน๊ต เพิ่มเติมน้ะจ้ะ
ที่อยากทำคือ export หมดทั้ง schema
expdp system/system_password_naja@XE schemas=schema_name_naja directory=DATA_PUMP_DIR dumpfile=filename_naja.dmp logfile=filename_naja.log
– ตอนแรก ไปใส่ directory ที่สร้างไว้ใน DIRECTORY ของ system แต่ดันเจอ error
ORA-39001: invalid argument value ORA-39000: bad dump file specification ORA-39145: directory object parameter must be specified and non-null
– ตอนแรกสร้าง Directory Name ต่อไปพอไปใส่ Database Server Directory ด้วยเออเร่อ เปลี่ยนเป็น
ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-29283: invalid file operation ORA-06512: at "SYS.UTL_FILE", line 536 ORA-29283: invalid file operation
ก้อดูเหมือนไม่ได้ช่วยอะไรมาก
สุดท้ายเลยเปลี่ยนไปใช้ DATA_PUMP_DIR แทนที่เป็น dir ที่สร้างขึ้น ซึ่งเราสามารถดู path ว่าแม่มไปเก็บไว้ที่ไหนได้จาก Query นี้
select directory_name, directory_path from dba_directories where directory_name like '%DATA_PUMP%';
path ของเราอยู่ที่ C:\oraclexe\app\oracle\admin\xe\dpdump\ น้ะจ้ะ
– ตอน import กลับ ทำเหมือนตอน export นี่แหละ ไม่มีปัญหามาก แต่ package หรือ function ที่ error ตั้งแต่แรก ที่ export มาอยู่แล้ว
oracle จะ แจ้ง error เป็น
ORA-39082: Object type PACKAGE_BODY:"schema_name_naja"."package_name_naja" created with compilation warnings
– เวงกรำ ดันไปเจอก้อน ที่ exp มา ( ไม่ใช่ expdp )
ORA-39143: dump file "filename_naja.DMP" may be an original export dump file
เลยต้องใช้นี่แทน
imp username_naja/userpassword_naja file=D:\oraclexe\app\oracle\admin\XE\dpdump\DATABASENAME.DMP log=SEISANK.log full=y
แต่ก็ไม่วายเจอปัญหา
IMP-00017: following statement failed with ORACLE error 2304: "CREATE TYPE "TYPENAME_NAJA" TIMESTAMP '2013-09-10:13:36:12' OID 'E600FB99B91976" "0EE04011ACA8A85B3F' AS OBJECT" "(" " bla_bla_bla VARCHAR2(2)" ");" IMP-00003: ORACLE error 2304 encountered ORA-02304: invalid object identifier literal
มีคน แนะนำให้ใช้ option TOID_NOVALIDATE
แต่ใช้แล้วมันก้อยังเหมือนเดิม
แมนนวลเอาจาก log ไป สร้างเองแม่ม
ถ้าเจอปัญหา
IMP-00013: only a DBA can import a file exported by another DBA IMP-00000: Import terminated unsuccessfully
มีคนบอกให้ grant import full database/export full database ให้ user แต่เราเองทำแล้วไม่หาย
เลยให้ sysdba import ให้แม่ม
imp system/system_pwd_naja fromuser=the_exported_user touser=the_user_we_want_to_put_stuff_in t file=D:\oraclexe\app\oracle\admin\XE\dpdump\filename_naja.dmp log=logname_ja.log
Tips from Robert Merkwürdigeliebe : to show the version of export server, or the encoding of the export/import server
#>imp username/password file=test.dmp show=y Import: Release 10.2.0.3.0 - Production on Fri Nov 26 08:38:47 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production With the Partitioning, OLAP and Data Mining options Export file created by EXPORT:V10.02.01 via conventional path import done in US7ASCII character set and AL16UTF16 NCHAR character set import server uses WE8ISO8859P1 character set (possible charset conversion)
ปัญหา encoding ที่ import done in AL32UTF8 ( UTF-8 ) แต่ export using JA16SJISTILDE ( Shift-JIS )
บน windows แก้โดยการเซต NLS_LANG ให้เหมือนกับ ที่ export มา
set NLS_LANG=JAPANESE_JAPAN.JA16SJISTILDE
NOTE :
oracle default user privilege naja
User Tab Default Tablespace : USERS Temporary Tablespace : TEMP Roles Tab Connect granted default Resource granted default System Privileges Tab Create synonym granted Create view granted Debug any procedure granted Debug connect session granted Execute any procedure granted Insert any table granted Select any table granted Unlimited tablespace granted Update any table granted