SQL Loader - Load Multiple Input Files Into Multiple Tables - Conditionally

So, what problem you are facing now?

I have three data files. Order1.csv, Order2.csv, Order3.csv. Each of these csv files contain order information from four different countries and order reference number. And I want to load them into multiple tables in Oracle using SQL Loader..

Order1.csv
IND,REF1101
AUS,REF1102
BRZ,REF1103
NZL,REF1104
SAF,REF1105

Order2.csv
IND,REF2101
AUS,REF2102
BRZ,REF2103
NZL,REF2104
SAF,REF2105

Order3.csv
IND,REF3101
AUS,REF3102
BRZ,REF3103
NZL,REF3104
SAF,REF3105

What are the tables into which you want to load this data?

I have three tables, IND, SA and rest of world. Using SQL Loader, I want all records with "IND" to get into the table TB_IND.Similarly, TB_SA for "SAF" and TB_REST for rest..

Do you have some simulation scripts?

Oh yes, I have them handy..here they are:

CREATE TABLE TB_IND
(
COUNTRY VARCHAR2(
10),
REFID VARCHAR2(
10)
)

CREATE TABLE TB_SA
(
COUNTRY VARCHAR2(
10),
REFID VARCHAR2(
10)
)

CREATE TABLE TB_REST
(
COUNTRY VARCHAR2(
10),
REFID VARCHAR2(
10)
)

What version of Oracle you are using?

Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product

Here is your Control file..Note that we have made use of WHEN clause in control file, to get the result

LOAD DATA
INFILE 'C:\ sqlldr\order1.csv'
INFILE 'C:\ sqlldr\order2.csv'
INFILE 'C:\ sqlldr\order3.csv'

  INTO TABLE TB_IND         
  WHEN COUNTRY = 'IND'
  (
                COUNTRY POSITION(1:3)  CHAR,
                REFID POSITION(5:11)  CHAR           
  )

  INTO TABLE TB_SA
  WHEN COUNTRY = 'SAF'
  (
                COUNTRY POSITION(1:3)  CHAR,
                REFID POSITION(5:11)  CHAR           
  )

  INTO TABLE TB_REST 
  WHEN COUNTRY != 'SAF'  AND COUNTRY != 'IND' 
  (
                COUNTRY POSITION(1:3)  CHAR,
                REFID POSITION(5:11)  CHAR           
  )

No comments:

Post a Comment