ในกรณีนี้ เป็นการ Export Data ออกจาก User หนึ่ง ไปยังอีก User หนึ่ง ซึ่งปัญหาที่พบคือ มีการ Export Import ก่อนหน้าแล้ว ด้วย Exp และ Imp แต่ คำสั่ง Imp นั้น จะไม่สามารถ Overwrite ตารางเก่าได้ หากมีการสร้างไว้แล้ว ซึ่ง Data Pump สามารถ ทำได้ ซึ่งเป็นคำสั่งใหม่ใน Oracle Version 10g ขึ้นไป
ตัวอย่างการ Export ด้วย Datapump
set NLS_LANG=English
expdp userid=[username]/[password]@[servicename] SCHEMAS=[schema name] dumpfile=[dumpfile name].dmp logfile=[log file name].log
เช่น username และ พาส คือ u กับ p มี service name ชื่อ mydatabase schemas เดิมชื่อ old1 จะได้ดังนี้
expdp userid=u/p@mydatabase SCHEMAS=old1 dumpfile=dumpdata.dmp logfile=dumpdata.log
จะ Export ไปชื่อไฟล์ dumpdata.dmp และมี log file dumpdata.log
this command for Export to dmp file and store in default folder.
ตัวอย่างการ Import ด้วย Datapump
set NLS_LANG=English
impdp [username]/[password]@[instance] dumpfile=[dumpfile name].dmp logfile=[log file name].log REMAP_SCHEMA=[old schema name]:[new schema name] table_exists_action=[options for table exists]
ตัวอย่าง
impdp u/p@mydatabase dumpfile=dumpdata.dmp logfile=importdumpdata.log REMAP_SCHEMA=old1:new1 table_exists_action=replace
ในที่นี้คือ นำเข้าไฟล์ โดยบันทึก log การนำเข้าในชื่อ importdumpdata.log และเปลี่ยน schema จาก old1 เป็น new1 ถ้า มี ตารางอยู่แล้ว ให้ทำการ drop และ นำเข้าไปใหม่
สำหรับ option ของ table_exists_action มีดังนี้
TABLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | REPLACE}
รายละเอียดต่าง ๆ สามารถดูเพิ่มเติมได้ที่
ref:http://docs.oracle.com/cd/B13789_01/server.101/b10825/dp_import.htm
ref:https://oracle-base.com/articles/10g/oracle-data-pump-10g