`
aries211
  • 浏览: 60866 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
最近访客 更多访客>>
社区版块
存档分类
最新评论

Using the Oracle Bulk Loader -2

阅读更多


Overview

To use the Oracle bulk loader, you need a control file, which specifies how data should be loaded into the database; and a data file, which specifies what data should be loaded. You will learn how to create these files in turn.


Creating the Control File

A simple control file has the following form:
LOAD DATA
INFILE <datafile>
APPEND INTO TABLE <tablename>
FIELDS TERMINATED BY '<separator>'
(<list load="" to="" names="" attribute="" all="" of="">)</list></separator></tablename></datafile>
  • <datafile></datafile> is the name of the data file. If you did not give a file name extension for <datafile></datafile>, Oracle will assume the default extension ".dat". Therefore, it is a good idea to name every data file with an extension, and specify the complete file name with the extension.
  • <tablename> </tablename> is the name of the table to which data will be loaded. Of course, it should have been created already before the bulk load operation.
  • The optional keyword APPEND says that data will be appended to <tablename> </tablename> . If APPEND is omitted, the table must be empty before the bulk load operation or else an error will occur.
  • <separator></separator> specifies the field separator for your data file. This can be any string. It is a good idea to use a string that you know will never appear in the data, so the separator will not be confused with data fields.
  • Finally, list the names of attributes of <tablename> </tablename> that are set by your data file, separated by commas and enclosed in parentheses. This list need not be the complete list of attributes in the actual schema of the table, nor must it be arranged in the same order as the attributes when the table was created -- sqlldr will match attributes to by their names in the table schema. Any attributes unspecified in the list of attributes will be set to NULL.
As a concrete example, here are the contents of a control file test.ctl:
LOAD DATA
INFILE test.dat
INTO TABLE test
FIELDS TERMINATED BY '|'
(i, s)


Creating the Data File

Each line in the data file specifies one tuple to be loaded into <tablename> </tablename> . It lists, in order, values for the attributes in the list specified in the control file, separated by <separator></separator>. As a concrete example, test.dat might look like:
1|foo
2|bar
3| baz
Recall that the attribute list of test specified in test.ctl is (i, s), where i has the type int, and s has the type char(10). As the result of loading test.dat, the following tuples are inserted into test:
(1, 'foo')
(2, 'bar')
(3, ' baz')

Some Notes of Warning

评论

相关推荐

Global site tag (gtag.js) - Google Analytics