Home » RDBMS Server » Server Utilities » SQLLDR Case5 Load into multiple tables
SQLLDR Case5 Load into multiple tables [message #178300] Tue, 20 June 2006 09:25 Go to next message
swamy99
Messages: 30
Registered: June 2006
Member
Is there any way we can load the CSV file into multiple tables selecting only few fields from the csv into multiple tables?

Exampless from Utilities, SQLLDR, Case5 shows how to do with fixed width where you can specify the position when loading the data into multiple tables, but I am trying to load the specified fields from the CSV file into multiple tables. Is there anyway we can specify only required fields that can be loaded into multiple tables?
Re: SQLLDR Case5 Load into multiple tables [message #178301 is a reply to message #178300] Tue, 20 June 2006 09:30 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
http://www.orafaq.com/forum/t/26690/0/
http://www.orafaq.com/forum/m/170602/42800/?srch=boundfiller#msg_170602
Re: SQLLDR Case5 Load into multiple tables [message #178306 is a reply to message #178301] Tue, 20 June 2006 09:47 Go to previous messageGo to next message
swamy99
Messages: 30
Registered: June 2006
Member
Thanks for your reply. But the solution says you can load into one table.
But how do we load the selected columns into multiple tables from the same row?
Re: SQLLDR Case5 Load into multiple tables [message #178308 is a reply to message #178306] Tue, 20 June 2006 09:58 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Please Post a sample datafile, sample table ddl and how your end result should be.
Regards
Re: SQLLDR Case5 Load into multiple tables [message #178314 is a reply to message #178308] Tue, 20 June 2006 10:38 Go to previous messageGo to next message
swamy99
Messages: 30
Registered: June 2006
Member
Here is the scenario.

col1 col2 col3 col4 col5 col6 col7
123, 456, 789, 100, 111, 222, 333
123, 456, 444, 555, 666, 777, 888
123, 456, 555, 555, 567, 678, 789
123, 234, 345, 456, 567, 678, 789
987, 876, 765, 654, 543, 432, 321
987, 876, 123, 234, 345, 456, 567
.................................
.................................



The data is mapped into table 1 with
col1 -> FLD1
col2 -> FLD2
col4 -> FLD3
col6 -> FLD4
col7 -> FLD5

The data should go to table 1 is

FLD1 FLD2 FLD3 FLD4 FLD5
123 456 100 222 333
123 456 555 777 888
123 456 555 678 789
123 234 456 678 789
987 876 654 432 321
987 876 234 456 567


The data is mapped into table 2 with (As Primary keys)
col1 -> FLD6
col2 -> FLD7

The data should go into table2 is

FLD6 FLD7
123 456
123 234
987 876

Just like how it is done with "Case Study 5: Loading Data into Multiple Tables" but need it with CSV file.

Hope this helps.

[Updated on: Tue, 20 June 2006 11:32]

Report message to a moderator

Re: SQLLDR Case5 Load into multiple tables [message #178339 is a reply to message #178314] Tue, 20 June 2006 12:40 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
For the given sample, you can just use this.
Else we may need to doctor the file.
oracle@mutation#cat file.ctl
LOAD DATA
infile 'file.dat'
replace INTO TABLE one
FIELDS TERMINATED BY "," optionally enclosed by '"' trailing nullcols
(
c1,
c2,
dummycol3 filler,
c3,
dummycol5 filler,
c4,
c5
)
into table two
replace
FIELDS TERMINATED BY "," optionally enclosed by '"' trailing nullcols
(
c1 POSITION(1),
c2 POSITION(5)
)


oracle@mutation#cat file.dat
123,456,789,100,111,222,333
123,456,444,555,666,777,888
123,456,555,555,567,678,789
123,234,345,456,567,678,789
987,876,765,654,543,432,321
987,876,123,234,345,456,567


oracle@mutation#sqlldr userid=scott/tiger control=file.ctl

SQL*Loader: Release 9.2.0.4.0 - Production on Tue Jun 20 13:38:38 2006

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Commit point reached - logical record count 6

oracle@mutation#query mutation scott.one

        C1         C2         C3         C4         C5
---------- ---------- ---------- ---------- ----------
       123        456        100        222        333
       123        456        555        777        888
       123        456        555        678        789
       123        234        456        678        789
       987        876        654        432        321
       987        876        234        456        567

6 rows selected.

oracle@mutation#query mutation scott.two

        C1         C2
---------- ----------
       123        456
       123        456
       123        456
       123        234
       987        876
       987        876

6 rows selected.
Re: SQLLDR Case5 Load into multiple tables [message #178345 is a reply to message #178339] Tue, 20 June 2006 13:03 Go to previous messageGo to next message
swamy99
Messages: 30
Registered: June 2006
Member
Thanks for the solution, but still there is something that I am still concerned about. When loading into table two, we see lot of duplicates in there. I want the loader process to eliminate those duplicates during the load itself.
If we look closely in CASE 5, 'emp' table has only the distinct number of records where as 'proj' has multiple records for the same empno. I am looking for that kind of solution but since there are no conditions, can we still get it without the duplicates. Thanks
Re: SQLLDR Case5 Load into multiple tables [message #178347 is a reply to message #178345] Tue, 20 June 2006 13:51 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
You can apply some sql methods here. Let the table TWO be loaded "as-is" and fix the records later using sql means.
There are several restrictions here.
without a 'when' you cannot force the relation between parent and child record.
Re: SQLLDR Case5 Load into multiple tables [message #178587 is a reply to message #178339] Wed, 21 June 2006 11:36 Go to previous messageGo to next message
swamy99
Messages: 30
Registered: June 2006
Member
Still having problem with this solution given earlier.
I see while inserting in table two, the POSITION is being used. What if the field is variable and there are about more than 50 fields in a row?
Re: SQLLDR Case5 Load into multiple tables [message #179508 is a reply to message #178587] Tue, 27 June 2006 14:53 Go to previous message
swamy99
Messages: 30
Registered: June 2006
Member
Is there any way to split the field in the above example into two separate records if there is a ';' condition.

ex:
123,456,789,100,111,222,333;456
123,456,444,555,666,777,888;567
123,456,555,555,567,678,789
123,234,345,456,567,678,789
987,876,765,654,543,432,321;111
987,876,123,234,345,456,567


The first, second and fifth rows has ';', so it needs to split into two separate records. For the first record, split 333 for one record with 456 as second record keeping the above suggested solution.

What exactly I am looking for is, if there is any condition that we can apply based on the length of the field using 'WHEN' condition. Thanks.

[Updated on: Tue, 27 June 2006 15:43]

Report message to a moderator

Previous Topic: avoid archive log generation ???
Next Topic: ORA-01041: internal error. hostdef extension doesn't exist
Goto Forum:
  


Current Time: Thu Jul 04 19:44:05 CDT 2024