日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

sqlldr使用小記

系統 2290 0

?????? 需求:將txt文本格式的數據導入到oracle里面

? ? ?? 解決方案:使用sql*loader工具。

? ? ?? 遇到問題:

? ? ?? (1) Field in data file exceeds maximum length

?????? (2)ORA-01861: literal does not match format string

? ? ??

? ? ? ? 最近需要在不同的數據庫之間導入導出數據,我們就戲稱是搬運工。就像某礦泉水廣告說的一樣:我們不生產數據,我們只做數據的搬運工。回歸正題,在正式生產運行的時候,使用的IBM datastage工具進行數據轉化。但是,也會遇到導出一些數據進行開發使用,這種時候使用DS就有點像重型武器了,不劃算。這個時候,腳本就華麗麗的登場了。

? ? ?? 速度使用sqlldr命令,其關鍵參數?

?? ? userid -- Oracle 的 username/password[@servicename]
?? ?control -- 控制文件,可能包含表的數據
?? ?-------------------------------------------------------------------------------------------------------
?? ?log -- 記錄導入時的日志文件,默認為 控制文件(去除擴展名).log
?? ?bad -- 壞數據文件,默認為 控制文件(去除擴展名).bad
?? ?data -- 數據文件,一般在控制文件中指定。用參數控制文件中不指定數據文件更適于自動操作
?? ?errors -- 允許的錯誤記錄數,可以用他來控制一條記錄都不能錯
?? ?rows -- 多少條記錄提交一次,默認為 64
?? ?skip -- 跳過的行數,比如導出的數據文件前面幾行是表頭或其他描述
???

? ? 使用方法:[oralce@dboracle]$sqlldr user/passwd@orcl control=control.ctl

??? 其中,控制文件的編寫是重點。

? ? control.ctl內容如下:

??? load data???????????????????
?? ?infile 'bank.txt'????????????????????????????? --指定外部數據文件
?? ?append into table test.sqlldr_test?? --操作類型
?? ?fields terminated by ","????????????????? --數據中每行記錄用","分隔

? ? Optionally enclosed by '"' ? ? ? ? ? ? ? --數據中每個字段用'"'隔起時

?? ?trailing nullcols????????????????????????????? --表的字段沒有對應的值時允許為空
?? ?(block_id,
?? ?block_data_begin_date,
?? ?block_data_end_date,
?? ?period_id,
?? ?create_date,
?? ?rec_state,
?? ?state_date)

?? 注意:

?? (1)字段可以指定類型,否則認為是CHARACTER類型。
?? (2)表定義

?

??? create table test.SQLLDR_TEST
?? ?(
?? ?? BLOCK_ID????????????? INTEGER not null,
?? ?? BLOCK_DATA_BEGIN_DATE INTEGER,
?? ?? BLOCK_DATA_END_DATE?? INTEGER,
?? ?? PERIOD_ID???????????? VARCHAR2(8),
?? ?? CREATE_DATE?????????? DATE,
?? ?? REC_STATE???????????? VARCHAR2(3),
?? ?? STATE_DATE??????????? DATE
?? ?)
???? 此時,使用上述控制文件就會出現ORA-01861: literal does not match format string的錯誤,解決方案就是把DATE類型的寫出來,即

? ?? create_date? DATE ? "YYYY-MM-DD"

? ?? state_date ? DATE ? "YYYY-MM-DD"

? ? ??

? ?? 在導入數據的時候,也遇到Field in data file exceeds maximum length錯誤。搬出谷大神之后,有如下之文章:

?

?

Field exceeds

Symptoms

Loading long columns using sqlldr,the following error is reported:

" Record 1: Rejected - Error on table CRM_ATIC_HEADER_DIF, column LONG_DESC.
Field in data file exceeds maximum length "

Cause

In the control file,char(n) had to be specified for all the "varchar2" and "long" columns that were there in the table definition ??

Fix

1.Check if there are any LONG or VARCHAR2 columns in the table where the data has to be loaded

2.Check the control file to make sure whether char(n) has been included for those corresponding columns.

Taking the example of the above control file,if these changes are made:
3.Changing the control file by including char(n) will resolve the issue

? ? 由此可知,只需要把控制文件中的字符類型char(n) 中的n指定數據即可,如:

?

?? period_id?????????? char(8)?
???

? ? -the end-

?


?

?


?

? ? ? ?

sqlldr使用小記


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 独山县| 无为县| 安徽省| 万盛区| 本溪| 涿鹿县| 四子王旗| 巴林左旗| 阿拉善盟| 湾仔区| 达孜县| 荆门市| 曲沃县| 巴林左旗| 保靖县| 洮南市| 达孜县| 关岭| 永福县| 保亭| 武汉市| 当雄县| 乃东县| 洪泽县| 内乡县| 南部县| 五指山市| 苏尼特右旗| 龙江县| 郓城县| 永丰县| 临邑县| 尤溪县| 玉山县| 丰原市| 元阳县| 县级市| 体育| 信宜市| 黄浦区| 弋阳县|