Home » RDBMS Server » Server Utilities » Loading into multiple rows from same record from csv file
Loading into multiple rows from same record from csv file [message #179983] Thu, 29 June 2006 10:12 Go to next message
swamy99
Messages: 30
Registered: June 2006
Member
I am loading a datafile from csv delimited. Few of the records are to be loaded as multiple records. I am using decode to insert based on the terminator within that column and splitting that into multiple rows. Here is an example from a CSV file record.

1,1001,ABCD;BCDE;CDEF A1001;B1002;C1003

The record should be split such that the data looks like this
1 1001 'ABCD A1001' --as one column in a row
1 1001 'BCDE B1002' -- as second column in a row
1 1001 'CDEF C1003' -- as third column in a row

I tried using decode, substr and instr functions but able to load only the first row, but unable to get the other two rows as above. I know it can be achived by decode, substr and instr function where the position is to be calculated which I am missing here.
What if the data is variable like

1,1001,ABC;ABCD A200;A1001
1,1002,ABD;BCD;CDEF;DEFG A201;B102;C1003;D4001
......

and the column data looks like
1 1001 'ABC A200'
1 1001 'ABCD A1001'
1 1002 'ABD A201'
1 1002 'BCD B102'
1 1002 'CDEF C1003'
1 1002 'DEFG D4001'
.....


Any Help is appreciated. Thanks
Split the string into several records [message #180185 is a reply to message #179983] Fri, 30 June 2006 09:25 Go to previous messageGo to next message
swamy99
Messages: 30
Registered: June 2006
Member
How do we split the string in column C to have multiple records. The first characters before ';' should be concatenated with the first few characters after the space to the end of ';'. The same for the second set of characters, 'ABCD' which is after the first ';' should be concatenated with the string comming after the first ';' after the space. Here is the sample data and expecting to get the desired output.

Table TEST1
A B C
1 1001 ABC;ABCD A200;A1001
1 1002 ABD;BCD;CDEF;DEFG A201;B102;C1003;D4001

into table TEST2
A B C
1 1001 ABC A200
1 1001 ABCD A1001
1 1002 ABD A201
1 1002 BCD B102
1 1002 CDEF C1003
1 1002 DEFG D4001


Re: Loading into multiple rows from same record from csv file [message #180222 is a reply to message #179983] Fri, 30 June 2006 18:52 Go to previous message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
There was a similar problem here:

http://www.orafaq.com/forum/t/64894/43710/
Previous Topic: SQL*Loader question
Next Topic: IMPORT Problem NEED HELP quickly
Goto Forum:
  


Current Time: Fri Jul 05 18:48:08 CDT 2024