Solved

SQL Loader control file

Posted on 2009-04-10
25
1,371 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
ID: 24118494
Can you examine the log file and see whats the error?
0
 

Author Comment

by:srikanthradix
ID: 24118605
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
ID: 24118634
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
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
ID: 24118665
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
ID: 24118680
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
ID: 24118738

--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
ID: 24118749
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
ID: 24118784
@ajexpert:
it is still not loading into table2.
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 24118790
can u send  me the log file?
0
 

Author Comment

by:srikanthradix
ID: 24118815
Please find the log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 24118838
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
ID: 24118910
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
 

Author Comment

by:srikanthradix
ID: 24118916
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
ID: 24118928
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
ID: 24118997
It is still not loading. Please find the log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 24119008
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
ID: 24119046
no load again. log file attached.

data.txt
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 24119070
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
ID: 24119161
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
ID: 24119182
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
ID: 24119201
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
ID: 24119277
table1 and table2 structures attached.

table-structure.txt
0
 
LVL 14

Accepted Solution

by:
ajexpert earned 500 total points
ID: 24119842
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
ID: 31569029
Thank you for your effort and time.
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 24119889
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

770 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