# 導出
exp scott/pass@orcl file=emp.dmp log=exp.log tables=emp
# 導入 (用戶映射)
imp orcl/pass@orcl fromuser=scott touser=orcl file=emp.dmp log=imp.log tables=emp
# 導出
expdp system/pass@orcl directory=dp_dir dumpfile=emp.dmp log=exp.log tables=scott.emp
# 導入 (Schema 重映射)
impdp system/pass@orcl directory=dp_dir dumpfile=emp.dmp log=imp.log tables=scott.emp remap_schema=scott:orcl
IMP-00017: ORA-00942: table or view does not exist
-- ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "DEPT" ("DEPTNO")
解決:先導入參照表、或導入時 CONSTRAINTS=N 稍後手動建約束。
ALTER TABLE emp MOVE TABLESPACE orcl;
ALTER INDEX pk_emp REBUILD ONLINE TABLESPACE orcl;-- 權限授予
GRANT SELECT ON scott.emp TO orcl;
-- 切換用戶
CONN orcl/pass
-- 重建
CREATE TABLE emp AS SELECT * FROM scott.emp;
WHERE 條件不成立 → 僅建空表結構-- 跨用戶複製
COPY FROM scott/pass@orcl TO orcl/pass@orcl REPLACE emp USING SELECT * FROM emp;
-- 同用戶換表空間 (先改默認表空間)
ALTER USER scott DEFAULT TABLESPACE orcl;
COPY FROM scott/pass@orcl TO scott/pass@orcl REPLACE emp USING SELECT * FROM emp;
-- REPLACE 會刪除舊表
| 方案 | 適用場景 | 複製約束 | LONG 支援 | 停機時間 |
|---|---|---|---|---|
| Expdp/Impdp | 跨 Schema/跨庫/異構 | ✅ | ✅ | 導出期無、導入期有 |
| MOVE | 同 Schema 換表空間 | ❌ (索引失效) | ❌ | 執行期間鎖表 |
| CTAS | 跨 Schema 簡單複製 | ❌ | ❌ | 極短 |
| COPY | 含 LONG/LOB、跨用戶 | ❌ | ✅ | 執行期間鎖表 |