| 特性 | LOAD | IMPORT |
|---|---|---|
| 資料來源 | 檔案、游標、管道、裝置 | 僅檔案 |
| 寫入方式 | 直接格式化頁寫入磁碟,不經緩衝池 | 逐列 INSERT,經緩衝池 |
| 約束檢查 | 延後至 Delete Phase 統一檢查 | 逐列即時檢查 |
| 日誌記錄 | 最小化(可設 NONRECOVERABLE) | 完整記錄每列 |
| 效能 | 大量資料載入快數倍 | 適合小量資料 |
| 可恢復性 | 需搭配 COPY YES/TSM 或備份 | 完全可恢復 |
READ ACCESS,將索引從暫存空間複製回目標表空間。四階段全部完成才算作業結束;任一階段失敗均進入「Load Pending」狀態,需 RESTART 或 TERMINATE 解除。
declare mycur cursor for select * from org;
create table org2 like org;
load from mycur of cursor insert into org2;
-- 建立目標表與例外表
create table staff1 like staff;
insert into staff1 select * from staff where id <= 160;
create table staffexp like staff1;
alter table staffexp add column time timestamp; -- 至少需 timestamp 欄位
-- 建立唯一索引製造衝突
create unique index idxstaff on staff1(id);
-- 匯出資料並載入(含違規資料)
export to d:staff.txt of del select * from staff;
load from d:staff.txt of del insert into staff1 for exception staffexp;
違規列寫入 staffexp,原表僅載入合規資料。若未指定例外表則直接捨棄。
-- 故意破壞第 32 列格式
load from d:staff.txt of del modified by dumpfile=d:dump insert into staff1 for exception staffexp;
格式錯誤列導向 dump.000;約束違規列導向例外表。兩者互補,確保資料不遺失。
load from d:staff.txt of del rowcount 3 insert into staff1;
load from d:staff.txt of del warningcount 1 insert into staff1;
-- 超過 1 個警告即中止,表進入 Load Pending
-- 解除:load from d:staff.txt of del terminate into staff1;
-- 修正後續傳:load from d:staff.txt of del restart into staff1;
load from d:staff.txt of del modified by norowwarnings insert into staff1;
-- 完整統計
load from d:staff.txt of del replace into staff1 statistics yes with distribution and detailed indexes all;
-- 簡略統計
load from d:staff.txt of del replace into staff1 statistics yes and indexes all;
create table staff1 like staff;
alter table staff1 add constraint chk check(dept < 100);
-- 載入違規資料導致 Check Pending
load from d:staff.txt of del insert into staff1;
-- 解除
set integrity for staff1 check immediate unchecked;
| 參數/修飾符 | 效用 | 適用場景 |
|---|---|---|
NONRECOVERABLE | 標記不可恢復,前滾忽略,表空間不進入 Backup Pending | 可重建的暫存資料、測試環境 |
COPY NO(預設) | 歸檔日誌啟用時,載入後表空間進入 Backup Pending,需備份才可寫入 | 生產環境標準模式 |
COPY YES | 載入變更同步寫入磁帶/目錄/TSM,表空間不進入 Backup Pending | 高可用性需求 |
FASTPARSE | 減少資料檢查,假設輸入資料乾淨 | DEL/ASC 格式、確定資料正確時 |
ANYORDER | 不保留輸入順序,SMP 系統上配合 CPU_PARALLELISM > 1 提升平行度 | 大量載入、SMP 環境 |
DATA BUFFER | 指定 4K 頁面數作為內部緩衝區 | 大量載入,適當加大有助效能 |
CPU_PARALLELISM | 指定解析/轉換/格式化的進程/執行緒數 | 僅 SMP 系統 |
DISK_PARALLELISM | 指定寫入磁碟的平行度 | 多磁碟陣列環境 |
COPY YES 或事後立即備份,確保可恢復。runstats 或載入時開啟 STATISTICS,避免優化器使用過時統計。TERMINATE 釋放鎖定,再決定 RESTART 或重新載入。