關於SQL*LODER的使用方法

來源:互聯網
上載者:User
關於SQL*LODER的使用方法 發表:2005-5-19 12:41:53 出處:你的部落格網(yourblog.org)

[文章來源:]

SQL*Loder的使用方法

從網上找到的,留做備用。

文/範生
  SQL*LOADER是ORACLE的資料載入工具,通常用來將作業系統檔案遷移到ORACLE資料庫中。SQL*LOADER是大型資料
倉庫選擇使用的載入方法,因為它提供了最快速的途徑(DIRECT,PARALLEL)。現在,我們拋開其理論不談,用執行個體來使
您快速掌握SQL*LOADER的使用方法。
  首先,我們認識一下SQL*LOADER。
  在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.
用法: 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 p
ath data saves
(預設: 常規路徑 64, 所有直接路徑)
bindsize -- Size of conventional path bind array in bytes(預設65536)
silent -- Suppress messages during run (header,feedback,errors,discards,part
itions)
direct -- use direct path (預設FALSE)
parfile -- parameter file: name of file that contains parameter specification
s
parallel -- do parallel load (預設FALSE)
file -- File to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions(默
認FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unus
able(預設FALSE)
commit_discontinued -- commit loaded rows when load is discontinued(預設FALSE)
readsize -- Size of Read buffer (預設1048576)
PLEASE NOTE: 命令列參數可以由位置或關鍵字指定
。前者的例子是 ’sqlload
scott/tiger foo’;後者的例子是 ’sqlload control=foo
userid=scott/tiger’.位置指定參數的時間必須早於
但不可遲於由關鍵字指定的參數。例如,
’SQLLOAD SCott/tiger control=foo logfile=log’, 但
’不允許 sqlload scott/tiger control=foo log’,即使允許
參數 ’log’ 的位置正確。
d:/oracle>
我們可以從中看到一些基本的協助資訊,這裡,我用到的是中文的WIN2000 ADV SERVER。
  我們知道,SQL*LOADER只能匯入純文字,所以我們現在開始以執行個體來講解其用法。
  一、已存在資料來源result.csv,欲倒入ORACLE中FANCY使用者下。
    result.csv內容:
  1,預設 Web 網站,192.168.2.254:80:,RUNNING
  2,other,192.168.2.254:80:test.com,STOPPED
  3,third,192.168.2.254:81:thirdabc.com,RUNNING
  從中,我們看出4列,分別以逗號分隔,為變長字串。
  二、制定控制檔案result.ctl
result.ctl內容:
load data
infile ’result.csv’
into table resultxt
(resultid char terminated by ’,’,
website char terminated by ’,’,
ipport char terminated by ’,’,
status char terminated by whitespace)
  說明:
  infile 指資料來源檔案 這裡我們省略了預設的 discardfile result.dsc badfile result.bad
  into table resultxt 預設是INSERT,也可以into table resultxt APPEND為追加方式,或REPLACE
  terminated by ’,’ 指用逗號分隔
  terminated by whitespace 結尾以空白分隔
  三、此時我們執行載入:
D:/>sqlldr userid=fancy/testpass control=result.ctl log=resulthis.out
SQL*Loader: Release 8.1.6.0.0 - Production on 星期二 1月 8 10:25:42 2002
(c) Copyright 1999 Oracle Corporation. All rights reserved.
SQL*Loader-941: 在描述表RESULTXT時出現錯誤
ORA-04043: 對象 RESULTXT 不存在
  提示出錯,因為資料庫沒有對應的表。
  四、在資料庫建立表
  create table resultxt
(resultid varchar2(500),
website varchar2(500),
ipport varchar2(500),
status varchar2(500))
/
  五、重新執行載入
  D:/>sqlldr userid=fancy/k1i7l6l8 control=result.ctl log=resulthis.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
  已經成功!我們可以通過記錄檔來分析其過程:resulthis.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.
控制檔案: result.ctl
資料檔案: result.csv
錯誤檔案: result.bad
廢棄檔案: 未作指定
:
(可廢棄所有記錄)
裝載數: ALL
跳過數: 0
允許的錯誤: 50
綁定數組: 64 行,最大 65536 位元組
繼續: 未作指定
所用路徑: 常規
表RESULTXT
已載入從每個邏輯記錄
插入選項對此表INSERT生效
列名 位置 長度 中止 封裝資料類型
------------------------------ ---------- ----- ---- ---- ---------------------
RESULTID FIRST * , CHARACTER
WEBSITE NEXT * , CHARACTER
IPPORT NEXT * , CHARACTER
STATUS NEXT * WHT CHARACTER
表RESULTXT:
3 行載入成功
由於資料錯誤, 0 行沒有載入。
由於所有 WHEN 子句失敗, 0 行沒有載入。
由於所有欄位都為空白的, 0 行沒有載入。
為結合數組分配的空間: 65016位元組(63行)
除綁定數組外的記憶體空間分配: 0位元組
跳過的邏輯記錄總數: 0
讀取的邏輯記錄總數: 3
拒絕的邏輯記錄總數: 0
廢棄的邏輯記錄總數: 0
從星期二 1月 08 10:31:57 2002開始運行
在星期二 1月 08 10:32:00 2002處運行結束
經過時間為: 00: 00: 02.70
CPU 時間為: 00: 00: 00.10(可
  六、並行作業
  sqlldr userid=/ control=result1.ctl direct=true parallel=true
sqlldr userid=/ control=result2.ctl direct=true parallel=true
sqlldr userid=/ control=result2.ctl direct=true parallel=true
當載入大量資料時(大約超過10GB),最好抑制日誌的產生:
  SQL>ALTER TABLE RESULTXT nologging;
這樣不產生REDO LOG,可以提高效率。然後在CONTROL檔案中load data上面加一行:unrecoverable
此選項必須要與DIRECT共同應用。
  在並行作業時,ORACLE聲稱可以達到每小時處理100GB資料的能力!其實,估計能到1-10G就算不錯了,開始可用結構
相同的檔案,但只有少量資料,成功後開始載入大量資料,這樣可以避免時間的浪費。

  綜上所述,SQL*LOADER的速成教程已經結束,條件分支等用法需要大家在日後工作中積累,我的觀點是“用起來”,
然後再深造。興趣是人類的第一教師,此話一點不錯。始終讓自己保持對技術的熱情比埋頭苦讀更重要,技術的道路未必艱辛,
卻是孤獨的,能夠忍受寂寞的人,才可能實現事業與人生的豐收。

SQLLOAD keyword=value [,keyword=value,...]

Valid Keywords:

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 (Default all)
skip -- Number of logical records to skip (Default 0)
load -- Number of logical records to load (Default all)
errors -- Number of errors to allow (Default 50)
rows -- Number of rows in conventional path bind array or between direct s
(Default: Conventional path 64, Direct path all)
bindsize -- Size of conventional path bind array in bytes (Default 65536)
silent -- Suppress messages during run (header,feedback,errors,discards,par)
direct -- use direct path (Default FALSE)
parfile -- parameter file: name of file that contains parameter specificatios
parallel -- do parallel load (Default FALSE)
file -- File to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions ()
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unu)
commit_discontinued -- commit loaded rows when load is discontinued (Default F)
readsize -- Size of Read buffer (Default 65535)

PLEASE NOTE: Command-line parameters may be specified either by
position or by keywords. An example of the former case is ’sqlload
scott/tiger foo’; an example of the latter is ’sqlload control=foo
userid=scott/tiger’. One may specify parameters by position before
but not after parameters specified by keywords. For example,
’sqlload scott/tiger control=foo logfile=log’ is allowed, but
’sqlload scott/tiger control=foo log’ is not, even though the
position of the parameter ’log’ is correct 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.