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
3 3045
Did you try anything to achieve this?
By the way pls post your table structure along with sample data.
Check this: -
SQL> ed
-
Wrote file afiedt.buf
-
-
1 create or replace procedure my_Data (p_list IN VARCHAR2,p_ret_data OUT VARCHAR2) IS
-
2 plist VARCHAR2(10000) := NULL;
-
3 /*TYPE my_dat is RECORD(field1 my_test.field1%type,
-
4 field2 my_test.field2%type,
-
5 field3 my_test.field3%type,
-
6 type my_test.type1%type);*/
-
7 TYPE mydat IS TABLE OF my_test%rowtype;
-
8 my_rec mydat ;
-
9 BEGIN
-
10 plist := CHR(39)||REPLACE(p_list,',',CHR(39)||','||CHR(39))||CHR(39);
-
11 EXECUTE IMMEDIATE 'SELECT field1,field2,field3,type1 FROM my_Test
-
12 WHERE type1 IN ('||plist||')' bulk collect into my_rec;
-
13 FOR I IN my_rec.first..my_rec.last LOOP
-
14 p_ret_data := p_ret_Data||my_rec(i).field1||','||my_rec(i).field2||','||
-
15 my_rec(i).field3||','||my_rec(i).type1||CHR(10);
-
16 end loop;
-
17* end;
-
SQL> /
-
-
SQL> var my_cur varchar2(4000)
-
-
SQL> exec my_data('type1,string1',:my_cur);
-
-
SQL> print :my_cur;
-
-
MY_CUR
-
----------------------------
-
1,hh,2,type1
-
1,hh,2,string1
-
-
SQL> exec my_data('type1',:my_cur);
-
-
PL/SQL procedure successfully completed.
-
-
SQL> print :my_cur
-
-
MY_CUR
-
-----------------------------------------------
-
1,hh,2,type1
-
-
SQL>
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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
...
|
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};
...
|
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....
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |