티스토리 뷰

시스템 서버

oracle 대용량 데이터 입력 - sqlldr

달리는개발자 2012. 11. 2. 21:31

Oracle에서 대량 데이터를 Database에 입력하기 위해 SQL*Loader를 사용한다.

SQL*Loader가 이해할 수 있는 Control 파일과 실제 데이터가 들어있는 Data 파일을 작성한다. Control 파일에는 데이터가 어디에 있는지, 어떻게 분석하고 해석할지 그리고 어디에 데이터를 넣야되는지 SQL*Loader에서 알려주는 역할을 한다.

 

 

Control 파일 생성

user.ctl

load data
characterset UTF8
infile 'user.dat'  "str '||\n'"
badfile 'user.bad'
discardfile 'user.dsc'
append
into table USER
fields terminated by ',' 
trailing nullcols
(
user_id,
reg_dt timestamp 'YYYY-MM-DD HH24:MI:SSXFF',
description char(4000)
)

 

Data 파일 생성

user.dat

shuiky, '2012-11-14 17:54:55', 설명||
shuiky2, '2012-11-14 17:54:55', 설명2

 

실행

sqlldr USERID=사용자 아이디/비밀번호 CONTROL=user.ctl LOG=user.log

 

 

sqlldr 사용법

oracle@socool[/home/oracle/sqlldr]$sqlldr

SQL*Loader: Release 10.2.0.1.0 - Production on Wed Nov 14 18:06:26 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Usage: SQLLDR keyword=value [,keyword=value,...]

Valid Keywords:

    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          (Default all)
      skip -- number of logical records to skip    (Default 0)
      load -- number of logical records to load    (Default all)
    errors -- number of errors to allow            (Default 50)
      rows -- number of rows in conventional path bind array or between direct path data saves
               (Default: Conventional path 64, Direct path all)
  bindsize -- size of conventional path bind array in bytes  (Default 256000)
    silent -- suppress messages during run (header,feedback,errors,discards,partitions)
    direct -- use direct path                      (Default FALSE)
   parfile -- parameter file: name of file that contains parameter specifications
  parallel -- do parallel load                     (Default FALSE)
      file -- file to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions  (Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable  (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued  (Default FALSE)
  readsize -- size of read buffer                  (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE  (Default NOT_USED)
columnarrayrows -- number of rows for direct path column array  (Default 5000)
streamsize -- size of direct path stream buffer in bytes  (Default 256000)
multithreading -- use multithreading in direct path
 resumable -- enable or disable resumable for current session  (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE  (Default 7200)
date_cache -- size (in entries) of date conversion cache  (Default 1000)

PLEASE NOTE: Command-line parameters may be specified either by
position or by keywords.  An example of the former case is 'sqlldr
scott/tiger foo'; an example of the latter is 'sqlldr control=foo
userid=scott/tiger'.  One may specify parameters by position before
but not after parameters specified by keywords.  For example,
'sqlldr scott/tiger control=foo logfile=log' is allowed, but
'sqlldr scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.

 

Tip

시퀀스값을 입력하고 싶은 경우 control 파일을 다음과 같이 수정한다.

.. 중략 ...
trailing nullcols
(
QNA_ID "QNA_ID_SEQ.NEXTVAL"
)

 

다른 필드값을 입력하고 싶은 경우 control 파일을 다음과 같이 수정한다.

.. 중략 ...
trailing nullcols
(
TITLE "SUBSTR(REPLACE(REPLACE(:CONTENT, '\"', '"'), '''', '''), 0, 70)")
, REG_DT "TO_TIMESTAMP(:ACCEPT_DT, 'YYYY-MM-DD HH24:MI:SSXFF')"
)

 

참고

Oracle Database Utilities 11g Release 2 (11.2)

http://docs.oracle.com/cd/E11882_01/server.112/e22490/title.htm#BEGIN

http://www.orafaq.com/wiki/SQL*Loader_FAQ

 

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함