Oracle 5.0 Reference Manual page 1096

Table of Contents

Advertisement

FIELDS TERMINATED BY ',';
If instead you tried to read in the file with the statement shown following, it wouldn't work because it
instructs
LOAD DATA INFILE
LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY '\t';
The likely result is that each input line would be interpreted as a single field.
can be used to read files obtained from external sources. For example, many
LOAD DATA INFILE
programs can export data in comma-separated values (CSV) format, such that lines have fields
separated by commas and enclosed within double quotation marks, with an initial line of column
names. If the lines in such a file are terminated by carriage return/newline pairs, the statement shown
here illustrates the field- and line-handling options you would use to load the file:
LOAD DATA INFILE 'data.txt' INTO TABLE
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
If the input values are not necessarily enclosed within quotation marks, use
keywords.
ENCLOSED BY
Any of the field- or line-handling options can specify an empty string (''). If not empty, the
[OPTIONALLY] ENCLOSED BY
FIELDS TERMINATED
than one character. For example, to write lines that are terminated by carriage return/linefeed pairs, or
to read a file containing such lines, specify a
To read a file containing jokes that are separated by lines consisting of %%, you can do this
CREATE TABLE jokes
(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
joke TEXT NOT NULL);
LOAD DATA INFILE '/tmp/jokes.txt' INTO TABLE jokes
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\n%%\n' (joke);
FIELDS [OPTIONALLY] ENCLOSED BY
OUTFILE), if you omit the word OPTIONALLY, all fields are enclosed by the
An example of such output (using a comma as the field delimiter) is shown here:
"1","a string","100.20"
"2","a string containing a , comma","102.20"
"3","a string containing a \" quote","102.20"
"4","a string containing a \", quote and comma","102.20"
If you specify OPTIONALLY, the
that have a string data type (such as CHAR, BINARY, TEXT, or ENUM):
1,"a string",100.20
2,"a string containing a , comma",102.20
3,"a string containing a \" quote",102.20
4,"a string containing a \", quote and comma",102.20
Note that occurrences of the
them with the
ESCAPED BY
is possible to inadvertently generate output that cannot be read properly by
For example, the preceding output just shown would appear as follows if the escape character is
empty. Observe that the second field in the fourth line contains a comma following the quote, which
(erroneously) appears to terminate the field:
1,"a string",100.20
2,"a string containing a , comma",102.20
LOAD DATA INFILE
to look for tabs between fields:
tbl_name
and
FIELDS ESCAPED BY
BY,
LINES STARTING
LINES TERMINATED BY '\r\n'
controls quoting of fields. For output
ENCLOSED BY
character within a field value are escaped by prefixing
ENCLOSED BY
character. Also note that if you specify an empty
1076
Syntax
values must be a single character. The
BY, and
LINES TERMINATED BY
character is used only to enclose values from columns
before the
OPTIONALLY
FIELDS
values can be more
clause.
(SELECT ... INTO
character.
ENCLOSED BY
value, it
ESCAPED BY
LOAD DATA
INFILE.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents