|
Oracle Home |
|
Home > Oracle Database Administration (DBA) > Maintenance > Oracle SQL*Loader |
|
Oracle Database 10g Administration (DBA): Maintenance |
|---|
Oracle SQL*Loader |
|
SQL*Loader is an Oracle-supplied utility that allows you to load data from a flat file (the flat file must be formatted) into an Oracle database. SQL*Loader supports various load formats, selective loading, and multi-table loads. SQL*Loader utility (must be run at the OS level) use a control file which contains the way the data is formatted and inserted into the Oracle database. During the insert operation a discard, log and bad files are created. The log file is a record of SQL*Loader's activities during a load session. Where a row is not inserted in a table (constraint violations, not enough disk space, etc) a record is inserted in the bad file. Sometimes, in the control file there are some criteria that a record must meet before it is loaded. If the criteria is not meet the record is not inserted in the database but in the discard file. The discard file is optional.
The SQL*Loader is invoked by running the following command:
sqlldr scott/s control = C:\sqlloader.ctl
In this case the SQL*Loader connects to the database as scott and using the information provided in sqlloader.ctl file insert the data in the database.
Supposing we have a text file which contains data for SCOTT.DEPT1 table. Here is the content of the file C:\DEPT.txt :
SCOTT.DEPT1 table has the following description:
For this we create the following control file C:\sqlloader.ctl :
load data
The following command will insert the data in the DEPT table: sqlldr scott/s control = C:\sqlloader.ctl log = DEPTNO1.log discard = DEPTNO1.dis
The default behavior of SQL*Loader is to insert data in an empty table. If the table is not empty an error will occur. If we want to append data the APPEND parameter must be added in the control file. If we want to replace the old data with the new one the REPLACE parameter must be added. Here is an example using APPEND parameter:
load data APPEND
Also, the WHEN clause could be added to filter the data which will be inserted in the database:
load data
Data transformation is possible during the data load. The control file must be modified to allow this. Here is an example of control file which allow data transformation:
load data
Here are other examples where data is transformed at the column level: -> using sequences: (...) rec_no "SEQ_NAME.nextval", (...) -> modifying the data from the file: (...) hire_date POSITION(1:5) ":hire_date+1", (...) -> using a constant: (...) LOC constant "TORONTO" (...) -> using an Oracle function: (...) name POSITION(6:15) "upper(:name)" (...)
Load Fixed & Variable length data records
The example which use FIELDS TERMINATED BY "," allows variable length records, because the columns are delimited by "," (could be used any other sign). Sometimes we don't have delimiters and the columns are fixed length values. In this case the control file must be like:
load data
and the data file must have the content like:
ACOUNTING
10 OTTAWA
More information about this subject ( Oracle SQL*Loader ) you can get from www.in-oracle.com
When you invoke SQL*Loader, you can specify certain parameters to
establish session characteristics. Parameters can be entered in any
order, optionally separated by commas. You specify values for
parameters, or in some cases, you can accept the default without
entering a value.
This was taken from here.
SQL*Loader provides two methods for loading data:
|
|
Home > Oracle Database Administration (DBA) > Maintenance > Oracle SQL*Loader |
|
Different Romanian Links/ Linkuri romanesti diferite |
Disclaimer: The views expressed on this web site are my own and do not reflect the views of Oracle Corporation. You may use the information from this site only at your risk. Copyright (c) 2009-2011 Paul Catalin Tomoiu. All rights reserved.