sqlload

SQL*LOADER是ORACLE的數據載入工具,通常用來將作業系統檔案遷移到ORACLE資料庫中。SQL*LOADER是大型數據倉庫選擇使用的載入方法,因為它提供了最快速的途徑(DIRECT,PARALLEL)。

基本介紹

  • 中文名:sqlload
  • 外文名:暫無
  • 分類:例如:人物,歷史,學者
  • 定義:例如:人物,歷史
使用,優勢,關鍵字,套用舉例,數據裝載,

使用

在NT下,SQL*LOADER的啟動命令為SQLLDR,在UNIX下一般為sqlldr/sqlload。
如執行:
d:\oracle>sqlldr
SQL*Loader: Release 8.1.6.0.0 - Production on 星期二 1月 8 11:06:42 2002
(c) Copyright 1999 Oracle Corporation. All rights reserved.

優勢

一是可以直接被前台應用程式調用。如開源的COMPIERE企業管理套用系統,其就是採用Oracle的資料庫系統。在COMPIERE這個套用系統中,有一項很強大的功能,就是數據導入功能。其不但可以按現有的模板導入數據,而且,用戶還可以自定義導入的格式。這對於系統在基礎數據導入的時候,非常的有用。 但是,其這個功能的開發,確很簡單,因為其基本上都是直接調用後台資料庫系統中的SQLLoader模組。命令行模式的導入模組,可以直接被前台的應用程式調用,這是其最大的優勢。
二是可以從既定檔案中大量導入數據。利用SQLLoader工具,可以從既定檔案中,如逗號分隔設定檔案或者固定寬度的檔案,把這些檔案中的大量記錄按照一定的規則導入到Oracle資料庫系統中去。這個導入的效率比圖形界面來說,也要高的多。
三是可以實現把多個數據檔案合併成一個檔案。我們都知道,Oracle資料庫中,可以把一個資料庫套用所需要的數據存放在多個數據檔案中,以追求比較高的資料庫性能,以及比價高的資料庫安全性。但是,有時候,我們也可能需要把這幾個數據檔案合二為一,此時,就可以採用SQLLoader工具把它們進行合併。
四是修復、分離壞的記錄。有時候,我們需要導入的數據跟Oracle資料庫系統的數據表可能會存在一些衝突,導致數據導入的失敗。如可能需要導入的數據欄位太長,超過了數據表的最大長度限制,此時,就會導致數據導入的失敗。利用SQLLoader導入工具,可以把這些不符合規則的記錄分離出來,存放在一個獨立的檔案中。而符合規則的數據,則可以被正常的導入。如此的話,就可以提高數據導入的準確性。

關鍵字

用法: SQLLOAD 關鍵字 = 值 [,keyword=value,...]
有效的關鍵字:
userid – ORACLE username/password
control – Control file name
log – Log file name
bad – Bad file name
data – Data file name
discard – Discard file name
discardmax – Number of discards to allow (全部默認)
skip – Number of logical records to skip (默認0)
load – Number of logical records to load (全部默認)
errors – Number of errors to allow (默認50)
rows – Number of rows in conventional path bind array or between direct path data saves(默認: 常規路徑 64, 所有直接路徑)
bindsize – Size of conventional path bind array in bytes(默認65536)
silent – Suppress messages during run (header,feedback,errors,discards,partitions)
direct – use direct path (默認FALSE)
parfile – parameter file: name of file that contains parameter specifications
parallel – do parallel load (默認FALSE)
file – File to allocate extents from
readsize – Size of Read buffer (默認1048576)
skip_unusable_indexes – disallow/allow unusable indexes or index partitions(默認FALSE)
skip_index_maintenance – do not maintain indexes, mark affected indexes as unusable(默認FALSE)
commit_discontinued – commit loaded rows when load is discontinued(默認FALSE)

套用舉例

一、已存在數據源a檔案,欲導入ORACLE中scott用戶下
檔案a內容如下:
1,默認Web站點,192.168.1.2:80:,RUNNING
2,other,192.168.1.2:80:test,STOPPED
3,third,192.168.1.2:81:thirdabc,RUNNING
二、制定控制檔案a.ctl
a.ctl內容如下:
load data
infile ‘a’
into table a
(resultid char terminated by ‘,’,
website char terminated by ‘,’,
ipport char terminated by ‘,’,
status char terminated by whitespace)
說明:
infile  指數據源檔案
into table a 默認是INSERT,也可以into table a APPEND為追加方式,或REPLACE
terminated by ‘,’  指用逗號作為分隔設定
terminated by whitespace 結尾以空白分隔
三、在資料庫建立表a
create table a
(resultid varchar2(500),
website varchar2(500),
ipport varchar2(500),
status varchar2(500))
/
四、執行載入SQL LOADER
D:\>sqlldr userid=scott/tiger control=a.ctl log=a.out
SQL*Loader: Release 8.1.6.0.0 - Production on 星期二 1月 8 10:31:57 2002
(c) Copyright 1999 Oracle Corporation. All rights reserved.
達到提交點,邏輯記錄計數2
達到提交點,邏輯記錄計數3
已經成功!可以通過日誌檔案a.out來分析其過程

數據裝載

a、insert,為預設方式,在數據裝載開始時要求表為空
b、append,在表中追加新記錄
c、replace,刪除舊記錄,替換成新裝載的記錄
d、truncate,同上
如上控制檔案a.ctl中的 into table a (默認是INSERT,也可以into table a APPEND為追加方式,或REPLACE),即可以書寫成如下方式
insert into table a
append into table a
replace into table a

相關詞條

熱門詞條

聯絡我們