數(shù)據(jù)批量導(dǎo)入Oracle數(shù)據(jù)庫

字號:


    SQL*LOADER是大型數(shù)據(jù)
    倉庫選擇使用的加載方法,因為它提供了最快速的途徑(DIRECT,PARALLEL)?,F(xiàn)在,我們拋開其理論不談,用實例來使
    您快速掌握SQL*LOADER的使用方法。
    首先,我們認(rèn)識一下SQL*LOADER。
    在NT下,SQL*LOADER的命令為SQLLDR,在UNIX下一般為sqlldr/sqlload。
    如執(zhí)行: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 關(guān)鍵字 = 值 [,keyword=value,...]
    有效的關(guān)鍵字:
    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 (全部默認(rèn))
    skip -- Number of logical records to skip (默認(rèn)0)
    load -- Number of logical records to load (全部默認(rèn))
    errors -- Number of errors to allow (默認(rèn)50)
    rows -- Number of rows in conventional path bind array or between direct p
    ath data saves
    (默認(rèn): 常規(guī)路徑 64, 所有直接路徑)
    bindsize -- Size of conventional path bind array in bytes(默認(rèn)65536)
    silent -- Supdivss messages during run (header,feedback,errors,discards,part
    itions)
    direct -- use direct path (默認(rèn)FALSE)
    parfile -- parameter file: name of file that contains parameter specification
    s
    parallel -- do parallel load (默認(rèn)FALSE)
    file -- File to allocate extents from
    skip_unusable_indexes -- disallow/allow unusable indexes or index partitions(默認(rèn)FALSE)
    skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable(默認(rèn)FALSE)
    commit_discontinued -- commit loaded rows when load is discontinued(默認(rèn)FALSE)
    readsize -- Size of Read buffer (默認(rèn)1048576)
    PLEASE NOTE: 命令行參數(shù)可以由位置或關(guān)鍵字指定。
    前者的例子是 'sqlload scott/tiger foo';
    后者的例子是 'sqlload control=foo userid=scott/tiger'.
    位置指定參數(shù)的時間必須早于但不可遲于由關(guān)鍵字指定的參數(shù)。例如,
    'SQLLOAD SCott/tiger control=foo logfile=log',
    但'不允許 sqlload scott/tiger control=foo log',
    即使允許參數(shù) 'log' 的位置正確。
    d:oracle>
    我們可以從中看到一些基本的幫助信息,這里,我用到的是中文的WIN2000 ADV SERVER。
    我們知道,SQL*LOADER只能導(dǎo)入純文本,所以我們現(xiàn)在開始以實例來講解其用法。
    一、已存在數(shù)據(jù)源result.csv,欲倒入ORACLE中FANCY用戶下。
    result.csv內(nèi)容:
    1,默認(rèn) 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內(nèi)容:
    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 指數(shù)據(jù)源文件 這里我們省略了默認(rèn)的 discardfile result.dsc badfile result.bad
    into table resultxt 默認(rèn)是INSERT,也可以into table resultxt APPEND為追加方式,或REPLACE
    terminated by ',' 指用逗號分隔
    terminated by whitespace 結(jié)尾以空白分隔
    三、此時我們執(zhí)行加載:
    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時出現(xiàn)錯誤
    ORA-04043: 對象 RESULTXT 不存在
    提示出錯,因為數(shù)據(jù)庫沒有對應(yīng)的表。
    四、在數(shù)據(jù)庫建立表
    create table resultxt
    (resultid varchar2(500),
    website varchar2(500),
    ipport varchar2(500),
    status varchar2(500))