数据批量导入Oracle数据库
生活随笔
收集整理的這篇文章主要介紹了
数据批量导入Oracle数据库
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
倉庫選擇使用的加載方法,因?yàn)樗峁┝俗羁焖俚耐緩?#xff08;DIRECT,PARALLEL)。現(xiàn)在,我們拋開其理論不談,用實(shí)例來使
您快速掌握SQL*LOADER的使用方法。
首先,我們認(rèn)識一下SQL*LOADER。
在NT下,SQL*LOADER的命令為SQLLDR,在UNIX下一般為sqlldr/sqlload。
如執(zhí)行:dracle>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' 的位置正確。
dracle>
? ?? ?我們可以從中看到一些基本的幫助信息,這里,我用到的是中文的WIN2000 ADV SERVER。
我們知道,SQL*LOADER只能導(dǎo)入純文本,所以我們現(xiàn)在開始以實(shí)例來講解其用法。
一、已存在數(shù)據(jù)源result.csv,欲倒入ORACLE中FANCY用戶下。
result.csv內(nèi)容:
1,默認(rèn) Web 站點(diǎn),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 不存在
提示出錯,因?yàn)閿?shù)據(jù)庫沒有對應(yīng)的表。
四、在數(shù)據(jù)庫建立表
??create table resultxt
??(resultid varchar2(500),
? ?website varchar2(500),
? ?ipport varchar2(500),
? ?status varchar2(500))
/
五、重新執(zhí)行加載
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.
達(dá)到提交點(diǎn),邏輯記錄計(jì)數(shù)2
達(dá)到提交點(diǎn),邏輯記錄計(jì)數(shù)3
已經(jīng)成功!我們可以通過日志文件來分析其過程:resulthis.out內(nèi)容如下:
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
數(shù)據(jù)文件: result.csv
錯誤文件: result.bad
廢棄文件: 未作指定
:
(可廢棄所有記錄)
裝載數(shù): ALL
跳過數(shù): 0
允許的錯誤: 50
綁定數(shù)組: 64 行,最大 65536 字節(jié)
繼續(xù):? ? 未作指定
所用路徑:? ?? ? 常規(guī)
表RESULTXT
已載入從每個邏輯記錄
插入選項(xiàng)對此表INSERT生效
? ?列名? ?? ?? ?? ?? ?? ?? ?? ?位置? ?? ?長度??中止 包裝數(shù)據(jù)類型
------------------------------ ---------- ----- ---- ---- ---------------------
RESULTID? ?? ?? ?? ?? ?? ?? ?? ?? ? FIRST? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
WEBSITE? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?NEXT? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
IPPORT? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? NEXT? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
STATUS? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? NEXT? ???*??WHT? ?? ?CHARACTER? ?? ?? ???
表RESULTXT:
3 行載入成功
由于數(shù)據(jù)錯誤, 0 行沒有載入。
由于所有 WHEN 子句失敗, 0 行沒有載入。
由于所有字段都為空的, 0 行沒有載入。
為結(jié)合數(shù)組分配的空間:? ? 65016字節(jié)(63行)
除綁定數(shù)組外的內(nèi)存空間分配:? ?? ?? ?0字節(jié)
跳過的邏輯記錄總數(shù):? ?? ???0
讀取的邏輯記錄總數(shù):? ?? ???3
拒絕的邏輯記錄總數(shù):? ?? ???0
廢棄的邏輯記錄總數(shù):? ?? ???0
從星期二 1月??08 10:31:57 2002開始運(yùn)行
在星期二 1月??08 10:32:00 2002處運(yùn)行結(jié)束
經(jīng)過時間為: 00: 00: 02.70
CPU 時間為: 00: 00: 00.10(可
六、并發(fā)操作
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
? ? 當(dāng)加載大量數(shù)據(jù)時(大約超過10GB),最好抑制日志的產(chǎn)生:
SQL>ALTER TABLE RESULTXT nologging;
? ? 這樣不產(chǎn)生REDO LOG,可以提高效率。然后在CONTROL文件中l(wèi)oad data上面加一行:unrecoverable
? ? 此選項(xiàng)必須要與DIRECT共同應(yīng)用。
在并發(fā)操作時,ORACLE聲稱可以達(dá)到每小時處理100GB數(shù)據(jù)的能力!其實(shí),估計(jì)能到1-10G就算不錯了,開始可用結(jié)構(gòu)
? ? 相同的文件,但只有少量數(shù)據(jù),成功后開始加載大量數(shù)據(jù),這樣可以避免時間的浪費(fèi)。
我的示例:
一、在數(shù)據(jù)庫建立表格weather如下:
create table weather(
outlook varchar(20),
temperature float,
humidity float,
windy varchar(10),
play varchar(10)
)
二、在F盤建立兩個文件 分別如下:
#1、result.ctl內(nèi)容如下:
load data
infile 'result.csv'
into table weather
(outlook char terminated by ',',
temperature??char terminated by ',',
humidity char terminated by ',',
windy char terminated by ',',
play char terminated by ','
)
#2、result.csv內(nèi)容如下:
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no
三、命令行下執(zhí)行
F:>sqlldr userid=cqsb/ctbujx123??control=result.ctl
www.jhaccp.com.cn
您快速掌握SQL*LOADER的使用方法。
首先,我們認(rèn)識一下SQL*LOADER。
在NT下,SQL*LOADER的命令為SQLLDR,在UNIX下一般為sqlldr/sqlload。
如執(zhí)行:dracle>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' 的位置正確。
dracle>
? ?? ?我們可以從中看到一些基本的幫助信息,這里,我用到的是中文的WIN2000 ADV SERVER。
我們知道,SQL*LOADER只能導(dǎo)入純文本,所以我們現(xiàn)在開始以實(shí)例來講解其用法。
一、已存在數(shù)據(jù)源result.csv,欲倒入ORACLE中FANCY用戶下。
result.csv內(nèi)容:
1,默認(rèn) Web 站點(diǎn),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 不存在
提示出錯,因?yàn)閿?shù)據(jù)庫沒有對應(yīng)的表。
四、在數(shù)據(jù)庫建立表
??create table resultxt
??(resultid varchar2(500),
? ?website varchar2(500),
? ?ipport varchar2(500),
? ?status varchar2(500))
/
五、重新執(zhí)行加載
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.
達(dá)到提交點(diǎn),邏輯記錄計(jì)數(shù)2
達(dá)到提交點(diǎn),邏輯記錄計(jì)數(shù)3
已經(jīng)成功!我們可以通過日志文件來分析其過程:resulthis.out內(nèi)容如下:
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
數(shù)據(jù)文件: result.csv
錯誤文件: result.bad
廢棄文件: 未作指定
:
(可廢棄所有記錄)
裝載數(shù): ALL
跳過數(shù): 0
允許的錯誤: 50
綁定數(shù)組: 64 行,最大 65536 字節(jié)
繼續(xù):? ? 未作指定
所用路徑:? ?? ? 常規(guī)
表RESULTXT
已載入從每個邏輯記錄
插入選項(xiàng)對此表INSERT生效
? ?列名? ?? ?? ?? ?? ?? ?? ?? ?位置? ?? ?長度??中止 包裝數(shù)據(jù)類型
------------------------------ ---------- ----- ---- ---- ---------------------
RESULTID? ?? ?? ?? ?? ?? ?? ?? ?? ? FIRST? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
WEBSITE? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?NEXT? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
IPPORT? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? NEXT? ???*? ? ,? ?? ?CHARACTER? ?? ?? ?? ?
STATUS? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? NEXT? ???*??WHT? ?? ?CHARACTER? ?? ?? ???
表RESULTXT:
3 行載入成功
由于數(shù)據(jù)錯誤, 0 行沒有載入。
由于所有 WHEN 子句失敗, 0 行沒有載入。
由于所有字段都為空的, 0 行沒有載入。
為結(jié)合數(shù)組分配的空間:? ? 65016字節(jié)(63行)
除綁定數(shù)組外的內(nèi)存空間分配:? ?? ?? ?0字節(jié)
跳過的邏輯記錄總數(shù):? ?? ???0
讀取的邏輯記錄總數(shù):? ?? ???3
拒絕的邏輯記錄總數(shù):? ?? ???0
廢棄的邏輯記錄總數(shù):? ?? ???0
從星期二 1月??08 10:31:57 2002開始運(yùn)行
在星期二 1月??08 10:32:00 2002處運(yùn)行結(jié)束
經(jīng)過時間為: 00: 00: 02.70
CPU 時間為: 00: 00: 00.10(可
六、并發(fā)操作
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
? ? 當(dāng)加載大量數(shù)據(jù)時(大約超過10GB),最好抑制日志的產(chǎn)生:
SQL>ALTER TABLE RESULTXT nologging;
? ? 這樣不產(chǎn)生REDO LOG,可以提高效率。然后在CONTROL文件中l(wèi)oad data上面加一行:unrecoverable
? ? 此選項(xiàng)必須要與DIRECT共同應(yīng)用。
在并發(fā)操作時,ORACLE聲稱可以達(dá)到每小時處理100GB數(shù)據(jù)的能力!其實(shí),估計(jì)能到1-10G就算不錯了,開始可用結(jié)構(gòu)
? ? 相同的文件,但只有少量數(shù)據(jù),成功后開始加載大量數(shù)據(jù),這樣可以避免時間的浪費(fèi)。
我的示例:
一、在數(shù)據(jù)庫建立表格weather如下:
create table weather(
outlook varchar(20),
temperature float,
humidity float,
windy varchar(10),
play varchar(10)
)
二、在F盤建立兩個文件 分別如下:
#1、result.ctl內(nèi)容如下:
load data
infile 'result.csv'
into table weather
(outlook char terminated by ',',
temperature??char terminated by ',',
humidity char terminated by ',',
windy char terminated by ',',
play char terminated by ','
)
#2、result.csv內(nèi)容如下:
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no
三、命令行下執(zhí)行
F:>sqlldr userid=cqsb/ctbujx123??control=result.ctl
www.jhaccp.com.cn
總結(jié)
以上是生活随笔為你收集整理的数据批量导入Oracle数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#设计模式--模板方法模式(学习Lea
- 下一篇: modscan