473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Comma Separated to Rows

29
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 output need to be of 5 rows with all the other fields repeated in all the rows

field1 field2 field3 Type
1 hh 2 data1
1 hh 2 type1
1 hh 2 string1
1 hh 2 tom


This should be my output while fetching the data from the database.


Thanks in advance
Aug 12 '10 #1
3 3045
OraMaster
135 100+
Did you try anything to achieve this?
By the way pls post your table structure along with sample data.
Aug 12 '10 #2
debasisdas
8,127 Expert 4TB
Read this.
Aug 12 '10 #3
amitpatel66
2,367 Expert 2GB
Check this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  create or replace procedure my_Data (p_list IN VARCHAR2,p_ret_data OUT VARCHAR2) IS
  5.   2  plist VARCHAR2(10000) := NULL;
  6.   3  /*TYPE my_dat is RECORD(field1 my_test.field1%type,
  7.   4                        field2 my_test.field2%type,
  8.   5                        field3 my_test.field3%type,
  9.   6                        type my_test.type1%type);*/
  10.   7  TYPE mydat IS TABLE OF my_test%rowtype;
  11.   8  my_rec mydat ;
  12.   9  BEGIN
  13.  10  plist := CHR(39)||REPLACE(p_list,',',CHR(39)||','||CHR(39))||CHR(39);
  14.  11  EXECUTE IMMEDIATE 'SELECT field1,field2,field3,type1 FROM my_Test
  15.  12                     WHERE type1 IN ('||plist||')' bulk collect into my_rec;
  16.  13  FOR I IN my_rec.first..my_rec.last LOOP
  17.  14  p_ret_data := p_ret_Data||my_rec(i).field1||','||my_rec(i).field2||','||
  18.  15                my_rec(i).field3||','||my_rec(i).type1||CHR(10);
  19.  16  end loop;
  20.  17* end;
  21. SQL> /
  22.  
  23. SQL> var my_cur varchar2(4000)
  24.  
  25. SQL> exec my_data('type1,string1',:my_cur);
  26.  
  27. SQL> print :my_cur;
  28.  
  29. MY_CUR
  30. ----------------------------
  31. 1,hh,2,type1
  32. 1,hh,2,string1
  33.  
  34. SQL> exec my_data('type1',:my_cur);
  35.  
  36. PL/SQL procedure successfully completed.
  37.  
  38. SQL> print :my_cur
  39.  
  40. MY_CUR
  41. -----------------------------------------------
  42. 1,hh,2,type1
  43.  
  44. SQL> 
  45.  
  46.  
Aug 17 '10 #4

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

Similar topics

1
by: Craig Keightley | last post by:
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 ...
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: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
5
by: Bob | last post by:
I think this is very simple but I am having difficult doing it. Basically take a comma separated list: abc, def, ghi, jk A list with only one token does not have any commas: abc The first...
9
by: phillip.s.powell | last post by:
Ok, you have three tables. You're supposed to be able to not only sort (ORDER BY) according to a_name, no problem, but you must also have the ability to sort (ORDER BY) the relationship between...
3
by: starman7 | last post by:
I'm attempting a query that gathers product data for a particular product id. One of the items is designer(s) which can be more than one. The product table has comma separated id's of the...
3
by: mahe23 | last post by:
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,...
10
by: Nishanth | last post by:
I want to know how to validate a string which is comma separated "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate each field value against a set of rules, for...
1
by: rythmik1 | last post by:
I need to create an alphabetized list from multiple rows that contain comma separated tags. Example: Row1 -> Lessons, Discussions, Help Row2 -> Discussions, Chat Row3 -> Surveys,...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.