程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 數據批量導入Oracle數據庫

數據批量導入Oracle數據庫

編輯: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 -- Supdivss 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 unusable(默認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))

 

  /

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved