sql loader的用法簡介

來源:互聯網
上載者:User

sql loader可以把一些以文字格式設定存放的資料順利的匯入到oracle資料庫中,
是一種在不同資料庫之間進行資料移轉的非常方便而且通用的工具。
缺點就速度比較慢,另外對blob等類型的資料就有點麻煩了。
用法: SQLLDR keyword=value [,keyword=value,...]
 
有效關鍵字:
    userid -- ORACLE username/password
   control – 控制檔案
       log – 記錄的記錄檔
       bad – 壞資料檔案
      data – 資料檔案
   discard – 丟棄的資料檔案
discardmax – 允許丟棄資料的最大值        (全部預設)
      skip -- Number of logical records to skip  (預設0)
      load -- Number of logical records to load  (全部預設)
    errors – 允許的錯誤記錄數          (預設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(預設256000)
                每次提交記錄的緩衝區的大小(位元組為單位,預設256000)
    silent --禁止輸出資訊 (header,feedback,errors,discards,partitions)
    direct – 使用直通路徑方式匯入                    (預設FALSE)
   parfile -- parameter file: name of file that contains parameter specifications
  parallel -- 並行匯入                   (預設FALSE)
       file -- File to allocate extents from
  與bindsize成對使用,其中較小者會自動調整到較大者
sqlldr先計算單條記錄長度,乘以rows,如小於bindsize,不會試圖擴張rows以填充bindsize;如超出,則以bindsize為準。
 
external_table
           -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE(預設NOT_USED)
columnarrayrows
           -- Number of rows for direct path column array(預設5000)
streamsize -- Size of direct path stream buffer in bytes(預設256000)
multithreading
           -- use multithreading in direct path
 resumable -- enable or disable resumable for current session(預設FALSE)
resumable_name
           -- text string to help identify resumable statement
resumable_timeout
           -- wait time (in seconds) for RESUMABLE(預設7200)
date_cache -- size (in entries) of date conversion cache(預設1000)
 
注意:有兩種方式可以指定命令列參數:通過位置或者通過關鍵字。前者的例子:'sqlldr scott/tiger foo';
後者的例子:'sqlldr control=foo userid=scott/tiger';
不能前面使用關鍵字指定後面通過位置制定的混合方式;
比如:'sqlldr scott/tiger control=foo logfile=log' 是允許的,
但'sqlldr scott/tiger control=foo log'不允許。
為清楚起見最好所有命令列參數都用關鍵字指定。
控制檔案:
一個控制命令的指令檔,通常以ctl結尾,內容如下:
LOAD DATA
INFILE 't.dat'              要匯入的檔案
// INFILE 'tt.date' 匯入多個檔案
// INFILE *               表示要匯入的內容就在control檔案裡 下面的BEGINDATA後面就是匯入的內容
 
INTO TABLE table_name    指定裝入的表
BADFILE 'c:\bad.txt'    可選,指定壞檔案地址,預設在目前的目錄下產生與原檔案名稱一致的.bad檔案
 
************* 以下是4種裝入表的方式
APPEND             原先的表有資料 就加在後面
INSERT             裝載空表 如果原先的表有資料 sqlloader會停止 預設值
REPLACE           原先的表有資料 原先的資料會全部刪除
TRUNCATE        指定的內容和replace的相同 會用truncate語句刪除現存資料
 
************* 指定分隔字元
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
// TERMINATED BY WRITESPACE 以空白分割
 
TRAILING NULLCOLS            表的欄位沒有對應的值時允許為空白
 
************* 下面是表的欄位
(
col_1 , col_2 ,col_filler FILLER // FILLER 關鍵字 此列的數值不會被裝載
// 如: lg,lg,not 結果 lg lg
)
如果沒聲明FIELDS TERMINATED BY ',' 時,可以用下面兩種方式實現同樣功能:
1.為每一列指定分隔字元
 (
 col_1 [interger external] TERMINATED BY ',' ,
 col_2 [date "dd-mon-yyy"] TERMINATED BY ',' ,
 col_3 [char] TERMINATED BY ',' OPTIONALLY ENCLOSED BY 'lg'
 )
2.用位置告訴欄位裝載資料
 (
col_1 position(1:2),
 col_2 position(3:10),
 col_3 position(*:16), // 這個欄位的開始位置在前一欄位的結束位置
 col_4 position(1:16),
 col_5 position(3:10) char(8) // 指定欄位的類型
 )
 
BEGINDATA         對應開始的 INFILE * 要匯入的內容就在control檔案裡
10,Sql,what
20,lg,show

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.