Using SQL Loader
Using SQL Loader
By Ahmed Baraka
Database
Tables
15,Accounting,"SARATOGA",..
16,OPERATIONS,"SARATOGA",..
10,"ACCOUNTING",CLEVELAND,..
12,RESEARCH,"SARATOGA",..
10,"ACCOUNTING",CLEVELAND,..
11,"ART",SALEM,..
10,"ACCOUNTING",CLEVELAND,..
11,"ART",SALEM,..
13,FINANCE,"BOSTON",..
11,"ART",SALEM,..
13,FINANCE,"BOSTON",..
21,"SALES",PHILA.,..
13,FINANCE,"BOSTON",..
21,"SALES",PHILA.,..
22,"SALES",ROCHESTER,..
21,"SALES",PHILA.,..
SQL*Loader
22,"SALES",ROCHESTER,..
42,"INT'L","SAN FRAN",..
22,"SALES",ROCHESTER,..
..42,"INT'L","SAN FRAN",..
..42,"INT'L","SAN FRAN",..
..
SQL*Loader rejected
Field Processing
accepted
Discard discarded Bad File
File (opt) Record Selection
selected
Server process
Log File rejected
inserted
Database
INFILE "sales1123.dat"
INTO TABLE sales23
FIELDS CSV WITH EMBEDDED
TRAILING NULLCOLS
(..
• Examples:
..
DEPTNO INTEGER EXTERNAL TERMINATED BY X'9',
..
• Example
LOAD DATA
INFILE 'mydatafile.dat'
APPEND
INTO TABLE EMP
...
• NULLIF can be specified at the table level and at the column level
• Example:
NULLIF = "NULL"
- Load the record if the value of the fifth column in the record is Y:
INTO TABLE STUDENT_COURSES
WHEN (5) = 'Y'
( ...
• Example:
INTO TABLE dept
TRAILING NULLCOLS
( deptno CHAR TERMINATED BY " ",
dname CHAR TERMINATED BY WHITESPACE,
loc CHAR TERMINATED BY WHITESPACE
)
10 Accounting
• We can sett a column to the current date/time using the SYSDATE parameter
- The column must be of DATE or character data type
- The parameter value is processed for each loaded batch
• The WHITESPACE delimiter includes spaces, tabs, blanks, line feeds, form
feeds, or carriage returns.
• SQL operators can be applied to field data with the SQL string
- The column name is used as a bind variable in the SQL string
Oracle Database Administration from Zero to Hero - a course by Ahmed Baraka
Setting a Column to a Unique Sequence Number
• The SEQUENCE parameter generates an incremented sequence number for a
particular column:
<col-name> SEQUENCE ( { COUNT | MAX | n } [,m])
Keyword Description
<col-name> The name of the column in the database to which to assign the sequence.
COUNT The sequence starts with the number of records already in the table plus the
increment.
MAX The sequence starts with the current maximum value for the column plus the
increment.
n Specifies the specific sequence number to begin with.
m The interment value (defaults to 1)