LOAD DATA INFILE * INTO TABLE test FIELDS TERMINATED BY ',' (i,s) BEGINDATA 1,foo 2,bar 3, baz 4,glorp 5,snarfThe purpose of this file is to load data into the relation test from the handout Getting Started With Oracle. Recall that this relation has two attributes, i and s, of types integer and char(10), respectively. The meaning of the lines, in order, are:
Notice that the third tuple in the load file above has a blank in front of baz. Thus, the value of attribute s for the third tuple is
' baz'that is, the four-character string with a blank in front. Later, we might search for tuples that have second component 'baz' and expect to find it, but we won't, because 'baz' and ' baz' are different strings.
LOAD DATA INFILE 'test.txt' APPEND INTO TABLE test FIELDS TERMINATED BY ',' (i,s)The meaning of these lines is as follows:
1,foo 2,bar 3, baz 4,glorp 5,snarfIf test were initially empty, then the final contents of test will be exactly the same as in the previous example.
CREATE TABLE Foo ( i INTEGER, d DATE );Then, in the control file, when you describe the attributes of the table being loaded, you follow them by their types; any attribute can be followed by its type, but in the example above, we shall specify a type for only the date-valued attribute d.
Following the DATE type is a date mask that describes
the format your date data will use.
The date mask is a double-quoted string with the following
conventions:
Here is an example load file.
Then comes a control file, the file in which the loader commands such as
the ones above, are found.
Finally, you have to give the name of another file, the log file, in
which some useful information will be placed by sqlldr to tell
you what it has done, including a discripition of any errors that occured
during the load.
For instance, if Sally, with password etaoinshrdlu wishes to
run the control file test.ctl and have the log output stored in
her file test.log, then (assuming she has the environment given
by file ~oracle/ora.env, as discussed in
Getting Started With
Oracle), Sally can execute:
LOAD DATA
INFILE *
INTO TABLE Foo
FIELDS TERMINATED BY ','
(i,d DATE "dd-mm-yyyy")
BEGINDATA
1,01-02-1234
2,3-4-1997
Notice that, as in the second data tuple above, a field can be shorter
than the corresponding field of the mask.
The punctuation - tells the loader that the day and month
fields of the second tuple terminate early.Using the Loader
sqlldr is a UNIX-level command, like sqlplus.
The form of a load command is:
sqlldr userid=<yourName>/<yourPasswd> control=<ctlFile> log=<logFile>
The arguments on the command line are a little unusual for UNIX
commands.
You have to follow the word userid (capitals OK) by an equal
sign and your login name, a slash, your password, the at-sign, and
cs.
The safer form of login, where you give your name and let the
system prompt you for a password, applies to sqlldr as well.
sqlldr userid=sally/etaoinshrdlu control=test.ctl log=test.log