Solved

SQL Loader control file

Posted on 2009-04-10
25
1,354 Views
Last Modified: 2013-12-12
This is the control file i am using to load into multiple tables. But, it is loading only into one table table1. Please suggest. I have copied the sample data into code block.

LOAD DATA
APPEND
INTO TABLE TABLE1 WHEN FILLERCOL = '1'
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
      COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
    , FILLERCOL         FILLER TERMINATED BY '|'
    , COLUMN2           INTEGER EXTERNAL
    , COLUMN3           INTEGER EXTERNAL
    , COLUMN4           INTEGER EXTERNAL
    , COLUMN5           INTEGER EXTERNAL
)
INTO TABLE TABLE2 WHEN FILLERCOL = '2'
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
      COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
    , FILLERCOL         FILLER TERMINATED BY '|'
    , COLUMN2           INTEGER EXTERNAL
    , COLUMN3           INTEGER EXTERNAL
    , COLUMN4           INTEGER EXTERNAL
    , COLUMN5           INTEGER EXTERNAL
)
2012076490|1|6835319,7140975,7411435,7232743

2012076490|2|658893,695333,695421,688091

2012076490|3|3899,29732,7288,178991,29941

2012131180|1|6835319,7140975,7411435,7232743

2012131180|2|658893,695333,695421,688091

2012131180|3|3899,29732,7288,178991

2012131180|4|GR000016,GR000017,GR000020,GR000002

2012189150|1|6835319,7140975,7411435,7232743

2012189150|2|658893,695333,695421,688091

2012189150|3|3899,29732,7288,178991

Open in new window

0
Comment
Question by:srikanthradix
  • 13
  • 12
25 Comments
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
Can you examine the log file and see whats the error?
0
 

Author Comment

by:srikanthradix
Comment Utility
Please find the log file attached.

I ran the sql loader like this.

$ sqlldr control = control.ctl data = data.txt log = data.log bad = data.bad discard = data.discard userid = $userid/$pass

SQL*Loader: Release 10.2.0.3.0 - Production on Fri Apr 10 15:38:57 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Commit point reached - logical record count 10



data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
Dude,
I dont think you are able to load in table1 too.
The data types in table and format in the file is not matching.  So is the error.
Tip:
Try loading only one record in one table till the data is successfully loaded in Table1.  Once you are set, you can load more records.
 
HTH
0
 

Author Comment

by:srikanthradix
Comment Utility
I apologize for that. I ftp'ed with ASCII format. Hence they were not loaded into table1
Please find the log file attached.

data.txt
0
 

Author Comment

by:srikanthradix
Comment Utility
In a site, i found this information regarding loading into multiple tables. But, i do not use position delimiter. please suggest.

http://www.orafaq.com/wiki/SQL*Loader_FAQ

Loading into multiple tables
One can also specify multiple "INTO TABLE" clauses in the SQL*Loader control file to load into multiple tables. Look at the following example:  LOAD DATA
 INFILE *
 INTO TABLE tab1 WHEN tab = 'tab1'
   ( tab  FILLER CHAR(4),
     col1 INTEGER
   )
 INTO TABLE tab2 WHEN tab = 'tab2'
   ( tab  FILLER POSITION(1:4),
     col1 INTEGER
   )
BEGINDATA
tab1|1
tab1|2
tab2|2
tab3|3
 
The "tab" field is marked as a FILLER as we don't want to load it.
Note the use of "POSITION" on the second routing value (tab = 'tab2'). By default field scanning doesn't start over from the beginning of the record for new INTO TABLE clauses. Instead, scanning continues where it left off. POSITION is needed to reset the pointer to the beginning of the record again.
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility

--instead of

TABLE TABLE2 WHEN FILLERCOL = '2'

can you try

INTO TABLE TABLE1 WHEN FILLERCOL <> '1'

Open in new window

0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
corrected post
--instead of

INTO TABLE TABLE2 WHEN FILLERCOL = '2'

--can you try

INTO TABLE TABLE2 WHEN FILLERCOL <> '1'

Open in new window

0
 

Author Comment

by:srikanthradix
Comment Utility
@ajexpert:
it is still not loading into table2.
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
can u send  me the log file?
0
 

Author Comment

by:srikanthradix
Comment Utility
Please find the log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
ok,
Lets try this.  Note both are inserting records into table1.
With this you should be able to load all 10 records in table1.
Let me know along with log file

--instead of

INTO TABLE TABLE1 WHEN FILLERCOL = '1'

--can you try

INTO TABLE TABLE1 WHEN FILLERCOL <> '1'

 

Open in new window

0
 

Author Comment

by:srikanthradix
Comment Utility
Do you want me to write like this? Sorry about that, i was a little confused.
LOAD DATA
APPEND
INTO TABLE TABLE1 WHEN FILLERCOL <> '1'
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
      COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
    , FILLERCOL         FILLER TERMINATED BY '|'
    , COLUMN2           INTEGER EXTERNAL
    , COLUMN3           INTEGER EXTERNAL
    , COLUMN4           INTEGER EXTERNAL
    , COLUMN5           INTEGER EXTERNAL
)
INTO TABLE TABLE2 WHEN FILLERCOL <> '1' AND FILLERCOL <> '3' AND FILLERCOL <> '4'
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
      COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
    , FILLERCOL         FILLER TERMINATED BY '|'
    , COLUMN2           INTEGER EXTERNAL
    , COLUMN3           INTEGER EXTERNAL
    , COLUMN4           INTEGER EXTERNAL
    , COLUMN5           INTEGER EXTERNAL
)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:srikanthradix
Comment Utility
Please note that rows which have FILLERCOL as 3 and 4 should be discarded. Sorry, i did not mention this before.
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
ok, try this.
6 records should be loaded in table1

LOAD DATA

APPEND

INTO TABLE TABLE1 WHEN FILLERCOL = '1'

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'

   , FILLERCOL         FILLER TERMINATED BY '|'

   , COLUMN2           INTEGER EXTERNAL

   , COLUMN3           INTEGER EXTERNAL

   , COLUMN4           INTEGER EXTERNAL

   , COLUMN5           INTEGER EXTERNAL

)

INTO TABLE TABLE1 WHEN FILLERCOL = '2' 

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'

   , FILLERCOL         FILLER TERMINATED BY '|'

   , COLUMN2           INTEGER EXTERNAL

   , COLUMN3           INTEGER EXTERNAL

   , COLUMN4           INTEGER EXTERNAL

   , COLUMN5           INTEGER EXTERNAL

)

Open in new window

0
 

Author Comment

by:srikanthradix
Comment Utility
It is still not loading. Please find the log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
can you try
LOAD DATA

APPEND

INTO TABLE TABLE1 WHEN FILLERCOL = '1'

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'

   , FILLERCOL         FILLER TERMINATED BY '|'

   , COLUMN2           INTEGER EXTERNAL

   , COLUMN3           INTEGER EXTERNAL

   , COLUMN4           INTEGER EXTERNAL

   , COLUMN5           INTEGER EXTERNAL

)

INTO TABLE TABLE1 WHEN FILLERCOL <> '1' 

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'

   , FILLERCOL         FILLER TERMINATED BY '|'

   , COLUMN2           INTEGER EXTERNAL

   , COLUMN3           INTEGER EXTERNAL

   , COLUMN4           INTEGER EXTERNAL

   , COLUMN5           INTEGER EXTERNAL

)

Open in new window

0
 

Author Comment

by:srikanthradix
Comment Utility
no load again. log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
strange...
what if you eliminate the WHEN CLAUSE altogether
Can you try the simple load without filter condition i.e. without WHEN
0
 

Author Comment

by:srikanthradix
Comment Utility
if i tried without the when condition all the records are getting loaded in the table1, none into table2. Please find the zip file which contains all the files.

sqlldr.zip
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
If data is being loaded in table1 but not in table2, means the datatype of table2 is not compatible with incoming data
Can you send me the structure of TABLE1 AND TABLE2
OR
Compare the structure of TABLE1 AND TABLE2.
0
 

Author Comment

by:srikanthradix
Comment Utility
Actually, i tried like this in reverse, it loaded into table2 but not into table1.

LOAD DATA
INFILE 'data.txt'
BADFILE 'data.bad'
DISCARDFILE 'data.discard'
APPEND
INTO TABLE TABLE2
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
   , FILLERCOL         FILLER TERMINATED BY '|'
   , COLUMN2           INTEGER EXTERNAL
   , COLUMN3           INTEGER EXTERNAL
   , COLUMN4           INTEGER EXTERNAL
   , COLUMN5           INTEGER EXTERNAL
)
INTO TABLE TABLE1
FIELDS TERMINATED BY ',' TRAILING NULLCOLS
(
     COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'
   , FILLERCOL         FILLER TERMINATED BY '|'
   , COLUMN2           INTEGER EXTERNAL
   , COLUMN3           INTEGER EXTERNAL
   , COLUMN4           INTEGER EXTERNAL
   , COLUMN5           INTEGER EXTERNAL
)


0
 

Author Comment

by:srikanthradix
Comment Utility
table1 and table2 structures attached.

table-structure.txt
0
 
LVL 14

Accepted Solution

by:
ajexpert earned 500 total points
Comment Utility
You have to make use of POSITION clause to force it reading file from start

LOAD DATA

APPEND

INTO TABLE TABLE1 WHEN FILLERCOL = '1'

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

      COLUMN1           INTEGER EXTERNAL TERMINATED BY '|'

    , FILLERCOL         FILLER TERMINATED BY '|'

    , COLUMN2           INTEGER EXTERNAL

    , COLUMN3           INTEGER EXTERNAL

    , COLUMN4           INTEGER EXTERNAL

    , COLUMN5           INTEGER EXTERNAL

)

INTO TABLE TABLE2 WHEN FILLERCOL = '2'

FIELDS TERMINATED BY ',' TRAILING NULLCOLS

(

      COLUMN1   POSITION(1)        INTEGER EXTERNAL TERMINATED BY '|'

    , FILLERCOL         FILLER TERMINATED BY '|'

    , COLUMN2           INTEGER EXTERNAL

    , COLUMN3           INTEGER EXTERNAL

    , COLUMN4           INTEGER EXTERNAL

    , COLUMN5           INTEGER EXTERNAL

)

Open in new window

0
 

Author Closing Comment

by:srikanthradix
Comment Utility
Thank you for your effort and time.
0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
Glad that I could help
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now