Oracle SQL*Loader Version 12.2 |
---|
General Information | |||||||
Library Note |
|
||||||
Note | SQL*Loader is a legacy tool focused on loading physical files, primarily fixed length and delimited into database tables. This page consists of a series of demonstrations of various SQL*Loader capabilities. It is by no means complete so you need to read the docs. It is also important to note that SQL*Loader has become, for all intents and purposes, a dinosaur tool and it is recommended that almost all activities be performed using External Tables (linked at page bottom). | ||||||
Common Syntax Elements | |||||||
SQL Loader Data Types |
|
||||||
Modes (or) Load Types |
|
||||||
BADFILE Records with formatting errors or that cause Oracle errors |
BADFILE '<file_name>' |
||||||
BADFILE 'sample.bad' |
|||||||
CHARACTERSET | CHARACTERSET <character_set_name> |
||||||
CHARACTERSET WE8MSWIN1252 |
|||||||
COLUMNARRAYROWS The number of rows to allocate for direct path column arrays |
COLUMNARRAYROWS <integer> |
||||||
COLUMNARRAYROWS 200 |
|||||||
CONTROL The name of the control file holding the parameters to be run |
CONTROL '<file_name>' |
||||||
See Demos Below |
|||||||
DATE_CACHE Specifies the date cache size (in entries, default 1000) |
DATE_CACHE = <integer> |
||||||
DATE_CACHE = 0 |
|||||||
DIRECT Specifies use of a direct path load (default FALSE) |
DIRECT |
||||||
See Demos 6 Below |
|||||||
DISCARDFILE and DISCARDMAX Records not satisfying a WHEN clause |
DISCARDFILE '<file_name>' |
||||||
See Demo 4 Below |
|||||||
ERRORS The maximum number of insert errors to allow |
ERRORS = <integer> |
||||||
ERRORS = 5 |
|||||||
FILE The database file from which to allocate new extents |
FILE=<file_path_and_name_string> |
||||||
FILE = C:\APP\ORACLE\PRODUCT\ORADATA\ORABASE\PDBDEV\UWDATA02.DBF |
|||||||
INFILE | INFILE * or INFILE '<file_name>' |
||||||
INFILE 'mydata.dat' "RECSIZE 80 BUFFERS 8" |
|||||||
INTO | INTO <table_name> |
||||||
INTO TABLE emp |
|||||||
LENGTH | LENGTH SEMANTICS <BYTE | CHAR> |
||||||
LENGTH SEMANTICS BYTE |
|||||||
LOAD The maximum number of logical records to load |
LOAD = <number of records to load> |
||||||
LOAD = 10000 |
|||||||
OPTIONS CLAUSE | BINDSIZE = n |
||||||
OPTIONS (BINDSIZE=100000, SILENT=(ERRORS, FEEDBACK)) |
|||||||
PATHS | CONVENTIONAL PATH |
||||||
See Demo 6 below |
|||||||
TERMINATORS |
|
||||||
TRAILING NULLCOLS | TRAILING NULLCOLS |
||||||
-- assuming this data |
|||||||
WHEN | WHEN <condition> |
||||||
See Demo 5 below |
|||||||
Assembling Logical Records | |||||||
CONCATENATE | CONCATENATE <number_of_physical_records> |
||||||
CONCATENATE 3 |
|||||||
CONTINUEIF THIS | CONTINUEIF THIS [PRESERVE] (start_position:end_position) = value |
||||||
CONTINUEIF THIS (1:2) = '%%' |
|||||||
CONTINUEIF NEXT | CONTINUEIF NEXT [PRESERVE] (start_position:end_position) = value |
||||||
CONTINUEIF NEXT (1:2) = '%%' |
|||||||
CONTINUEIF LAST | CONTINUEIF LAST (start_position:end_position) = value |
||||||
-- Tests against the last non-blank character. Allows only a single character for the test | |||||||
PRESERVE | Preserves the CONTINUEIF characters |
||||||
Demo Tables & Data | |||||||
Demo Tables | CREATE TABLE dept ( |
||||||
Demo 1 | |||||||
Basic import of delimited data with data in the control file | |||||||
Control File | OPTIONS (ERRORS=500, SILENT=(FEEDBACK)) |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo01.ctl log=d:\load\demo01.log |
|||||||
Demo 2 | |||||||
Basic import of fixed length data with separate data and control files | |||||||
Control File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo02.ctl log=c:\load\demo02.log |
|||||||
Demo 3 | |||||||
Append of delimited data with data in the control file. This sample demonstrates date formating, delimiters within delimiters and implementation of record numbering with a SQL*Loader sequence. APPEND indicates that the table need not be empty before the SQL*Loader is run. | |||||||
Control File | LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo03.ctl log=c:\load\demo3.log |
|||||||
Demo 4 | |||||||
Replace of fixed length data with separate data and control file. This sample demonstrates specifying a discard file, the maximum number of records to discard (DISCARDMAX), and CONTINUEIF (where it looks for an asterisk in the first position to determine if a new line has started). | |||||||
Control File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo04.ctl log=c:\load\demo4.log |
|||||||
Demo 5 | |||||||
Loading into multiple tables during an import using the WHEN keyword. The control file loads two different tables making three passes at one of them. Note the isse with the Doolittle record and how it is handled. | |||||||
Control File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo5.ctl log=d:\load\demo5.log |
|||||||
Demo 6 | |||||||
Using the NULLIF and BLANKS keywords to handle zero length strings being loaded into numeric columns. Also note the use of Direct Path Load in the control file (DIRECT=TRUE). | |||||||
Control File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo06.ctl log=c:\load\demo06.log DIRECT=TRUE |
|||||||
Demo 7 | |||||||
Using a buit-in function to modify data during loading | |||||||
Control File | LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass control=c:\load\demo07.ctl log=c:\load\demo07.log |
|||||||
Demo 8 | |||||||
Another example of using a built-in function, in this case DECODE, to modify data during loading | |||||||
Control File | LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo08.ctl log=c:\load\demo08.log |
|||||||
Demo 9 | |||||||
Loading multiple files into multiple tables in a singe control file. Note the use of the WHEN keyword. | |||||||
Control File Data File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo09.ctl log=c:\load\demo09.log |
|||||||
Demo 10 | |||||||
Loading negative numeric values. Note Clark and Miller's records in the data file. Note empty row. | |||||||
Control File Data File |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass@pdbdev control=c:\load\demo10.ctl log=c:\load\demo10.log |
|||||||
Demo 11 | |||||||
Loading XML | |||||||
Control File | LOAD DATA |
||||||
desc po_tab |
|||||||
Demo 12 | |||||||
Loading a CONSTANT, RECNUM, and SYSDATE | |||||||
Control File | OPTIONS (ERRORS=100, SILENT=(FEEDBACK)) |
||||||
ALTER TABLE dept |
|||||||
Demo 13 | |||||||
Setting READSIZE and BINDSIZE | |||||||
The control file and data for this demo can be found in /demo/schema/sales_history/ schema under
$ORACLE_HOME as cust1v3.ctl and cust1v3.dat BINDSIZE and READSIZE do not apply to Direct Path Loads |
LOAD DATA |
||||||
conn sh/sh@pdbdev |
|||||||
Demo 14 | |||||||
Sign Trailing | |||||||
Load Numbers with trailing + and - signs Be sure to also look up the keyword ZONED in the Oracle docs for another way to handle this type of data |
LOAD DATA |
||||||
sqlldr userid=uwclass/uwclass/pdbdev control=c:\load\demo14.ctl log=c:\load\demo14.log |
|||||||
Demo 15 | |||||||
Filler | |||||||
Ignoring information that should not be loaded | LOAD DATA |
||||||
sqlldr userid=scott/tiger@pdbdev control=c:\load\demo15.ctl log=c:\load\demo15.log |
|||||||
Demo 16 | |||||||
External Table Generation | |||||||
SQL*Loader used to generate external table DDL which can be found in the log file Control File Generated Log File |
LOAD DATA |
||||||
sqlldr userid=scott/tiger@pdbdev control=c:\load\demo16.ctl log=c:\load\demo16.log external_table=generate_only |
Related Topics |
Data Pump |
DBMS_LOB |
Export |
External Tables |
Import |
MultiMedia Audio |
MultiMedia Video |
UTL_FILE |
What's New In 21c |
What's New In 23c |
This site is maintained by Dan Morgan. Last Updated: | This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2023 Daniel A. Morgan All Rights Reserved | |||||||||
|
||||||||||