2.MISSING FIELD VALUES ARE NULL
MISSING FIELD VALUES ARE NULL indicates that if there is not enough data in a record for all fields,
then those fields with missing data values are set to NULL. If MISSING FIELD VALUES ARE NULL is not specified,
and there is not enough data in the record for all fields, then the row is rejected.
In the following example, the second record is stored with a NULL set for the year_of_birth column,
even though the data for the year of birth is missing from the datafile. If the MISSING FIELD VALUES ARE NULL
clause was omitted from the access parameters, then the second row would be rejected because it
did not have a value for the year_of_birth column. The example is followed by a sample of the datafile
that can be used to load it.
CREATE TABLE emp_load
(first_name CHAR(15),
last_name CHAR(20),
year_of_birth INT)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(FIELDS TERMINATED BY ","
MISSING FIELD VALUES ARE NULL
)
LOCATION ('foo.dat')
);
Alvin,Tolliver,1976
Baer,Kenneth
Mary,Dube,1973
3.trim_spec
The trim_spec clause is used to specify that spaces should be trimmed from the beginning of a text field, the end of a text field,
or both. Spaces include blanks and other nonprinting characters such as tabs, line feeds, and carriage returns.
The syntax for the trim_spec clause is as follows:
NOTRIM indicates that no characters will be trimmed from the field.
LRTRIM, LTRIM, and RTRIM are used to indicate that characters should be trimmed from the field.
LRTRIM means that both leading and trailing spaces are trimmed.
LTRIM means that leading spaces will be trimmed.
RTRIM means trailing spaces are trimmed.
LDRTRIM is used to provide compatibility with SQL*Loader trim features.
It is the same as NOTRIM except in the following cases:
If the field is not a delimited field, then spaces will be trimmed from the right.
If the field is a delimited field with OPTIONALLY ENCLOSED BY specified, and the optional enclosures are missing for a particular instance, then spaces will be trimmed from the left.
The default is LDRTRIM. Specifying NOTRIM yields the fastest performance.
The trim_spec clause can be specified before the field list to set the default trimming for all fields. If trim_spec is omitted before the field list, then LDRTRIM is the default trim setting. The default trimming can be overridden for an individual field as part of the datatype_spec.
If trimming is specified for a field that is all spaces, then the field will be set to NULL.
In the following example, all data is fixed-length; however, the character data will not be loaded with leading spaces. The example is followed by a sample of the datafile that can be used to load it.
CREATE TABLE emp_load (first_name CHAR(15), last_name CHAR(20),
year_of_birth CHAR(4))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (FIELDS LTRIM)
LOCATION ('foo.dat'));
Alvin, Tolliver,1976
Kenneth, Baer, 1963
Mary, Dube, 1973
4.delim_spec
The delim_spec clause is used to find the end (and if ENCLOSED BY is specified, the start) of a field. Its syntax is as follows:
Text description of et_delim_spec.gif follows
Text description of the illustration et_delim_spec.gif
If ENCLOSED BY is specified, the access driver starts at the current position in the record and skips over all whitespace looking for the first delimiter. All whitespace between the current position and the first delimiter is ignored. Next, the access driver looks for the second enclosure delimiter (or looks for the first one again if a second one is not specified). Everything between those two delimiters is considered part of the field.
If TERMINATED BY string is specified with the ENCLOSED BY clause, then the terminator string must immediately follow the second enclosure delimiter. Any whitespace between the second enclosure delimiter and the terminating delimiter is skipped. If anything other than whitespace is found between the two delimiters, then the row is rejected for being incorrectly formatted.
If TERMINATED BY is specified without the ENCLOSED BY clause, then everything between the current position in the record and the next occurrence of the termination string is considered part of the field.
If OPTIONALLY is specified, then TERMINATED BY must also be specified. The OPTIONALLY parameter means the ENCLOSED BY delimiters can either both be present or both be absent. The terminating delimiter must be present regardless of whether the ENCLOSED BY delimiters are present. If OPTIONALLY is specified, then the access driver skips over all whitespace, looking for the first nonblank character. Once the first nonblank character is found, the access driver checks to see if the current position contains the first enclosure delimiter. If it does, then the access driver finds the second enclosure string and everything between the first and second enclosure delimiters is considered part of the field. The terminating delimiter must immediately follow the second enclosure delimiter (with optional whitespace allowed between the second enclosure delimiter and the terminating delimiter). If the first enclosure string is not found at the first nonblank character, then the access driver looks for the terminating delimiter. In this case, all characters from the beginning (including the leading blanks) to the terminating delimiter are considered part of the field.
After the delimiters have been found, the current position in the record is set to after the last delimiter for the field. If TERMINATED BY WHITESPACE was specified, then the current position in the record is set to after all whitespace following the field.
A missing terminator for the last field in the record is not an error. The access driver proceeds as if the terminator was found. It is an error if the second enclosure delimiter is missing.
The string used for the second enclosure can be included in the data field by including the second enclosure twice. For example, if a field is enclosed by single quotation marks, a data field could contain a single quotation mark by doing something like the following:
'I don''t like green eggs and ham'
There is no way to quote a terminator string in the field data without using enclosing delimiters. Because the field parser does not look for the terminating delimiter until after it has found the enclosing delimiters, the field can contain the terminating delimiter.
In general, specifying single characters for the strings is faster than multiple characters. Also, searching data in fixed-width character sets is usually faster than searching data in varying-width character sets.
The following are some examples of using delim_spec:
TERMINATED BY "|"
ENCLOSED BY "\" TERMINATED BY ","
ENCLOSED BY "START MESSAGE" AND "END MESSAGE"
Example: External Table with Terminating Delimiters
The following is an example of an external table that uses terminating delimiters. It is followed by a sample of the datafile that can be used to load it.
CREATE TABLE emp_load (first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (FIELDS TERMINATED BY WHITESPACE)
LOCATION ('foo.dat'));
Alvin Tolliver 1976
Kenneth Baer 1963
Mary Dube 1973
Example: External Table with Enclosure and Terminator Delimiters
The following is an example of an external table that uses both enclosure and terminator delimiters. Remember that all whitespace between a terminating string and the first enclosure string is ignored, as is all whitespace between a second enclosing delimiter and the terminator. The example is followed by a sample of the datafile that can be used to load it.
CREATE TABLE emp_load (first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (FIELDS TERMINATED BY "," ENCLOSED BY "(" AND ")")
LOCATION ('foo.dat'));
(Alvin) , (Tolliver),(1976)
(Kenneth), (Baer) ,(1963)
(Mary),(Dube) , (1973)
Example: External Table with Optional Enclosure Delimiters
The following is an example of an external table that uses optional enclosure delimiters. Note that LRTRIM is used to trim leading and trailing blanks from fields. The example is followed by a sample of the datafile that can be used to load it.
CREATE TABLE emp_load (first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '(' and ')'
LRTRIM)
LOCATION ('foo.dat'));
Alvin , Tolliver , 1976
(Kenneth), (Baer), (1963)
( Mary ), Dube , (1973)