Search notes:

Oracle: SQL Loader Example: Selectively insert records according to a criteria

This example sort of uses a where condition (when ... = ...) to select the records that need to be loaded.

Create destination table

Create the table that is to be filled:
create table tq84_sql_loader_3 (
  field_1       varchar2(10),
  field_2       varchar2(10)
);
Github repository Oracle-Patterns, path: /SQLLoader/ex_03/create_table.sql

Control file

The control file specifies that only records need to be loaded whose 2nd field's value is fruit.
load data
infile 'load_3.dat' "str '\r\n'"
discardfile 'load_3.dsc'
insert
into table tq84_sql_loader_3
when field_2 = 'Fruit'
fields terminated by ';'
(
  field_1      char,
  field_2      char
)
Github repository Oracle-Patterns, path: /SQLLoader/ex_03/load_3.ctl

The data file

The name of this data file is specified with the infile statement in the control file.
Banana;Fruit;
Lemon;Fruit;
Avocado;Fruit
Ford;Car;
Pear;Fruit;
Apple;Fruit;
Github repository Oracle-Patterns, path: /SQLLoader/ex_03/load_3.dat

Load the data

$ sqlldr control=load_3.ctl userid=rene/password@ora.server.xy

Discarded records

One record didn't meet the load criterion. It is written into the discarded file load_3.dsc:
Ford;Car;

See also

Other SQL Loader examples
SQL*Loader

Index