473,468 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

converting comma separated values into rows in oracle

1 New Member
All,

How do One convert a comma separated column from a text file into rows in oracle. I have a scenario where the list of comma separated values changes dynamically.

It is like:

abc, ttt, 1,2,34,56,67,,

afg, ttt, 3,4,5,6,,,,,

try, ttt, 4,5,,

I need to load this data into a oracle table which has columns like this:


name time value_abc value_afg value_try

abc ttt 1

abc ttt 2......



afg ttt 3

afg ttt 4.....



try ttt 4

try ttt 5 and so on...

Thanks a bunch...
Jun 15 '06 #1
3 29569
masdi2t
37 New Member
All,

How do One convert a comma separated column from a text file into rows in oracle. I have a scenario where the list of comma separated values changes dynamically.

It is like:

abc, ttt, 1,2,34,56,67,,

afg, ttt, 3,4,5,6,,,,,

try, ttt, 4,5,,

I need to load this data into a oracle table which has columns like this:


name time value_abc value_afg value_try

abc ttt 1

abc ttt 2......



afg ttt 3

afg ttt 4.....



try ttt 4

try ttt 5 and so on...

Thanks a bunch...

you can use comma_to_table procedure from DBMS_UTILITY package.
i give you little ex.

i've a little table with 2 column, create table dest(x int, y char(1));
n this is d script:

DECLARE
plist VARCHAR2(50) := 'A,B,C,D,E,F,G,H,I,J';
ptablen BINARY_INTEGER;
ptab DBMS_UTILITY.uncl_array;
BEGIN
DBMS_OUTPUT.put_line('plist : ' || plist);
DBMS_UTILITY.comma_to_table (
list => plist,
tablen => ptablen,
tab => ptab);
FOR i IN 1 .. ptablen LOOP
INSERT INTO dest VALUES (i, ptab(i));
END LOOP;
END;
Aug 3 '06 #2
Medhatithi
33 New Member
you can use comma_to_table procedure from DBMS_UTILITY package.
i give you little ex.

i've a little table with 2 column, create table dest(x int, y char(1));
n this is d script:

DECLARE
plist VARCHAR2(50) := 'A,B,C,D,E,F,G,H,I,J';
ptablen BINARY_INTEGER;
ptab DBMS_UTILITY.uncl_array;
BEGIN
DBMS_OUTPUT.put_line('plist : ' || plist);
DBMS_UTILITY.comma_to_table (
list => plist,
tablen => ptablen,
tab => ptab);
FOR i IN 1 .. ptablen LOOP
INSERT INTO dest VALUES (i, ptab(i));
END LOOP;
END;
There are however, certain limitations for using this package. You must go through them in Oracle documentation to use it. Alternatively, you can use SUBSTR & INSTR to separate the values. I can give you a sample code:


declare
lc NUMBER(10):=1;
v_loanlen NUMBER(10);
v_len NUMBER(10);
v_start_sub NUMBER(10):=1;
v_end_sub NUMBER(10);
begin
v_loanlen:=length(p_loans);
LOOP
EXIT WHEN v_end_sub=v_loanlen;
v_end_sub:=INSTR(p_loans,',',1,lc)-1;
IF v_end_sub<0
THEN
v_end_sub:=v_loanlen;
END IF;
v_len:=v_end_sub-v_start_sub+1;
insert into table_name(column_name)
values(SUBSTR(p_loans,v_start_sub,v_len));
lc:=lc+1;
v_start_sub:=v_end_sub+2;
END LOOP;
Jun 8 '07 #3
dchamber
2 New Member
Here is a way to do it with straight SQL in Oracle. This uses the CSV string a,b,c,d ; However, it could be any string.

Expand|Select|Wrap|Line Numbers
  1. select substr(csv, 
  2.    instr(csv,',',1,lev) + 1, 
  3.    instr(csv,',',1,lev+1 )-instr(csv,',',1,lev)-1) 
  4. from 
  5.   (select ','||'a,b,c,d'||',' csv from dual), 
  6.   (select level lev from dual connect by level <= 100) 
  7. where lev <= length(csv)-length(replace(csv,','))-1;
Dec 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: RogerTBrick | last post by:
Cheers for the help last time guys. Again this is probably dead simple but try as I might, I just can't work it out. THe XML file I am being give contains some code value that need to be...
1
by: idog | last post by:
If I start off with a string which contains comma separated ints. I want to move this into an int array so i can do sorting. I thought I might get this to work: int test = {textBox1.Text}; ...
2
by: RD | last post by:
S= myTxtStrean.Readline gives me a string. How do I extract the fields separated by commas for instance 1,123456,345632,7876543 1,234567890,5432,87654 (values are not each the same length) ...
1
by: alister joseph | last post by:
hi I have two tables, i have to combine them & a column should contain comma separated value. example 1 a 2 b 2 c 2 d 3 a
4
by: flavourofbru | last post by:
Hi, In the datagridview control, one of my column has multiple values separated by a comma Is there a way to get individaual values which are separated by a comma from that particular cells? ...
10
by: Tony Johansson | last post by:
Hello! What does it mean when it says that there is no information about the data types of the data extracted from a CSV file. Can somebody this. //Tony
3
by: anil2083 | last post by:
How to migrate the comma separated values from one table to another table? suppose we have table i.e XYZ and we have comma separated values in few columns i.e( column_name and values are...
5
by: amkohl | last post by:
<script type="text/javascript">dcsMultiTrack('DCS.dcsuri','/a/b/c/d/e','DCS.dcsqry','_ABC=ABC_0001','DCSext.error_code','abc500','DCSext.error_desc','FAILURE','DCSext.error_type','ABC...
3
by: beulajo | last post by:
How to convert comma separated field value into respective rows in query? I have a field say Type="data1,type1,string1,tom" This is one field of a table which consists of 5 other fields My...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.