About SQL Loader: Overview
About SQL Loader: Overview
Overview:
SQL LOADER is an Oracle utility used to load data into table given a datafile which has the
records that need to be loaded. SQL*Loader takes data file , as well as a control file, to insert
data into the table. W hen a Control file is executed, it can create Three (3) files called log
Log file tells you the state of the tables and indexes and the number of logical records already
read from the input datafile. This information can be used to resume the load where it left off.
Bad file or reject file gives you the records that were rejected because of formatting errors or
because they caused Oracle errors.
Discard file specifies the records that do not meet any of the loading criteria like when any of the
WHEN clauses specified in the control file. These records differ from rejected records.
The data file can be in fixed record format or variable record format.
Fixed Record Format would look like the below. In this case you give a specific position where
Variable Record Format would like below where the data fields are separated by a delimiter.
Note: The Delimiter can be anything you like. In this case it is "|"
1196700|9|0|692.64
1378901|2|3900|488.62
1418700|2|2320|467.92
1418702|14|8740|4056.36
1499100|1|0|3.68
1632800|3|0|1866.66
1632900|1|70|12.64
1637600|50|0|755.5
OPTIONS (SKIP = 1) --The first row in the data file is skipped without loading
LOAD DATA
OPTIONALLY ENCLOSED BY '"' --the values of the data fields may be enclosed in "
TRAILING NULLCOLS -- columns that are not present in the record treated as null
"(TRIM(:EXT_COST))" ,
MONTH "to_char(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD-MON-YY')" ,
OPTION statement precedes the LOAD DATA statement. The OPTIONS parameter allows you
to specify runtime arguments in the control file, rather than on the command line. The following
ROW S = n -- Number of rows in conventional path bind array or between direct path data
BINDSIZE = n -- Size of conventional path bind array in bytes ( System -dependent default)
INFILE* specifies that the data is found in the control file and not in an external file. INFILE
'$FILE', can be used to send the filepath and filename as a parameter when registered as a
concurrent program.
LOAD DATA
INFILE '/home/vision/kap/import2.csv'
LOAD DATA
INFILE *
BEGINDATA
7369,SMITH,7902,Accounting
7499,ALLEN,7698,Sales
7521,WARD,7698,Accounting
7566,JONES,7839,Sales
7654,MARTIN,7698,Accounting
Example where file name and path is sent as a parameter when registered as a concurrent
program
LOAD DATA
INFILE '$FILE'
INSERT -- If the table you are loading is empty, INSERT can be used.
APPEND -- If data already exists in the table, SQL*Loader appends the new rows to it. If data
REPLACE -- All rows in the table are deleted and the new data is loaded
INTOTABLEis required to identify the table to be loaded into. In the above example INTO
TABLE "APPS"."BUDGET", APPS refers to the Schema and BUDGET is the Table name.
FIELDS TERMINATED BY specifies how the data fields are terminated in the datafile.(If the
OPTIONALLY ENCLOSED BY '"' specifies that data fields may also be enclosed by quotation
marks.
TRAILINGNULLCOLS clause tells SQL*Loader to treat any relatively positioned columns that
LOAD DATA
INFILE 'sample.dat'
name>
SQL*Loader loads the tables, 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.
Skip columns:
Load Data
--
--
--
TRAILING NULLCOLS
name Filler,
Empno ,
sal