SQL Loader Case Studies: SQLLDR
SQL Loader Case Studies: SQLLDR
Case Study 6: Loading Data Using the Direct Path Load Method
12-2
Case Study 1: Loading Variable-Length Data on page 12-5: Loads stream format
records in which the fields are terminated by commas and may be enclosed by
quotation marks. The data is found at the end of the control file.
Case Study 2: Loading Fixed-Format Fields on page 12-8: Loads data from a
separate datafile.
Case Study 3: Loading a Delimited, Free-Format File on page 12-11: Loads data
from stream format records with delimited fields and sequence numbers. The
data is found at the end of the control file.
Case Study 4: Loading Combined Physical Records on page 12-14: Combines
multiple physical records into one logical record corresponding to one database
row.
Case Study 5: Loading Data into Multiple Tables on page 12-18: Loads data into
multiple tables in one run.
Case Study 6: Loading Data Using the Direct Path Load Method on page 12-24:
Loads data using the direct path load method.
Case Study 7: Extracting Data from a Formatted Report on page 12-28: Extracts
data from a formatted report.
Case Study 8: Loading Partitioned Tables on page 12-34: Loads partitioned
tables.
Case Study 9: Loading LOBFILEs (CLOBs) on page 12-38: Adds a CLOB column
called resume to the table emp, uses a FILLER field (res_file), and loads
multiple LOBFILEs into the emp table.
Case Study 10: Loading REF Fields and VARRAYs on page 12-43: Loads a
customer table that has a primary key as its OID and stores order items in a
VARRAY. Loads an order table that has a reference to the customer table and the
order items in a VARRAY.
Case Study 11: Loading Data in the Unicode Character Set on page 12-47: Loads
data in the Unicode character set, UTF16, in little-endian byte order. This case
study uses character-length semantics.
If the sample data for the case study is contained in the control file, then there will
be no .dat file for that case.
If there are no special setup steps for a case study, there may be no .sql file for that
case. Starting (setup) and ending (cleanup) scripts are denoted by an S or E after the
case number.
Table 121 lists the files associated with each case.
Table 121
Case
.ctl
.dat
.sql
Yes
No
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes (S, E)
Yes
Yes
Yes
Yes
Yes
Yes
10
Yes
No
Yes
11
Yes
Yes
Yes
At the SQL prompt, use the SELECT statement to select all rows from the table
that the case study loaded. For example, if the table emp was loaded, enter:
SQL> SELECT * FROM emp;
12-4
A simple control file identifying one table and three columns to be loaded.
Including data to be loaded from the control file itself, so there is no separate
datafile. See Identifying Data in the Control File with BEGINDATA on
page 8-11.
Loading data in stream format, with both types of delimited fields: terminated
and enclosed. See Specifying Field Length for Datatypes for Which Whitespace
Can Be Trimmed on page 9-47.
LOAD DATA
INFILE *
INTO TABLE dept
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(deptno, dname, loc)
BEGINDATA
12,RESEARCH,"SARATOGA"
10,"ACCOUNTING",CLEVELAND
11,"ART",SALEM
13,FINANCE,"BOSTON"
21,"SALES",PHILA.
22,"SALES",ROCHESTER
42,"INT'L","SAN FRAN"
Notes:
1.
The LOAD DATA statement is required at the beginning of the control file.
2.
INFILE * specifies that the data is found in the control file and not in an
external file.
3.
The INTO TABLE statement is required to identify the table to be loaded (dept)
into. By default, SQL*Loader requires the table to be empty before it inserts any
records.
4.
5.
6.
At the SQL prompt, execute the SQL script for this case study, as follows:
SQL> @ulcase1
This prepares and populates tables for the case study and then returns you to
the system prompt.
3.
At the system prompt, invoke SQL*Loader and run the case study, as follows:
sqlldr USERID=scott/tiger CONTROL=ulcase1.ctl LOG=ulcase1.log
SQL*Loader loads the dept table, creates the log file, and returns you to the
system prompt. You can check the log file to see the results of running the case
study.
12-6
ulcase1.ctl
Data File:
ulcase1.ctl
Bad File:
ulcase1.bad
Discard File: none specified
(Allow all discards)
Number to load:
Number to skip:
Errors allowed:
Bind array:
Continuation:
Path used:
ALL
0
50
64 rows, maximum of 256000 bytes
none specified
Conventional
Table DEPT:
7 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
skipped:
read:
rejected:
discarded:
0
7
0
0
00:00:01.53
00:00:00.20
Notes:
1.
Position and length for each field are determined for each record, based on
delimiters in the input file.
2.
In this case, the field positions and datatypes are specified explicitly.
5)
LOAD DATA
INFILE 'ulcase2.dat'
INTO TABLE emp
(empno
POSITION(01:04)
INTEGER EXTERNAL,
ename
POSITION(06:15)
CHAR,
job
POSITION(17:25)
CHAR,
mgr
POSITION(27:30)
INTEGER EXTERNAL,
sal
POSITION(32:39)
DECIMAL EXTERNAL,
comm
POSITION(41:48)
DECIMAL EXTERNAL,
deptno
POSITION(50:51)
INTEGER EXTERNAL)
Notes:
12-8
1.
The LOAD DATA statement is required at the beginning of the control file.
2.
The name of the file containing data follows the INFILE parameter.
3.
The INTO TABLE statement is required to identify the table to be loaded into.
4.
Lines 4 and 5 identify a column name and the location of the data in the datafile
to be loaded into that column. empno, ename, job, and so on are names of
columns in table emp. The datatypes (INTEGER EXTERNAL, CHAR, DECIMAL
EXTERNAL) identify the datatype of data fields in the file, not of corresponding
columns in the emp table.
5.
CLARK
KING
MILLER
JONES
ALLEN
MARTIN
CHAN
MARTIN
MANAGER
PRESIDENT
CLERK
MANAGER
SALESMAN
SALESMAN
ANALYST
SALESMAN
7839
7782
7839
7698
7698
7566
7698
2572.50
5500.00
920.00
3123.75
1600.00
1312.50
3450.00
1312.50
10
10
10
20
300.00 30
1400.00 30
20
1400.00 30
At the SQL prompt, execute the SQL script for this case study, as follows:
SQL> @ulcase1
This prepares and populates tables for the case study and then returns you to
the system prompt.
3.
At the system prompt, invoke SQL*Loader and run the case study, as follows:
sqlldr USERID=scott/tiger CONTROL=ulcase2.ctl LOG=ulcase2.log
SQL*Loader loads the table, creates the log file, and returns you to the system
prompt. You can check the log file to see the results of running the case study.
Records loaded in this example from the emp table contain department
numbers. Unless the dept table is loaded first, referential integrity checking
rejects these records (if referential integrity constraints are enabled for the emp
table).
ALL
0
50
64 rows, maximum of 256000 bytes
none specified
Conventional
Table EMP:
7 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
logical
logical
logical
logical
records
records
records
records
skipped:
read:
rejected:
discarded:
0
7
0
0
.
.
.
Elapsed time was:
CPU time was:
00:00:00.81
00:00:00.15
Loading data (enclosed and terminated) in stream format. See Delimited Fields
on page 9-30.
Loading dates using the datatype DATE. See Datetime and Interval Datatypes
on page 9-16.
Using SEQUENCE numbers to generate unique keys for loaded data. See Setting
a Column to a Unique Sequence Number on page 9-60.
Using APPEND to indicate that the table need not be empty before inserting new
records. See Table-Specific Loading Method on page 8-34.
Using Comments in the control file set off by two hyphens. See Comments in
the Control File on page 8-4.
The data is in a different format than in case 2. Some data is enclosed in quotation
marks, some is set off by commas, and the values for deptno and projno are
separated by a colon.
1)
12-11
5)
Notes:
1.
Comments may appear anywhere in the command lines of the file, but they
should not appear in data. They are preceded with two hyphens that may
appear anywhere on a line.
2.
INFILE * specifies that the data is found at the end of the control file.
3.
APPEND specifies that the data can be loaded even if the table already contains
rows. That is, the table need not be empty.
4.
The default terminator for the data fields is a comma, and some fields may be
enclosed by double quotation marks (").
5.
6.
The SEQUENCE function generates a unique value in the column loadseq. This
function finds the current maximum value in column loadseq and adds the
increment (1) to it to obtain the value for loadseq for each row inserted.
7.
BEGINDATA specifies the end of the control information and the beginning of
the data.
8.
Although each physical record equals one logical record, the fields vary in
length, so that some records are longer than others. Note also that several rows
have null values for comm.