| Merging multiple rows into single row [message #319527] |
Mon, 12 May 2008 01:59  |
Brayan Messages: 276 Registered: November 2004 |
Senior Member |
|
|
Hi,
In a table X I have following values
BR CODE
-- ----
1001 1
1001 2
1001 3
1002 1
1002 2
1003 1
1003 2
I want to get o/p like this
BR CODE
-- ----
1001 1,2,3
1002 1,2
1003 1,2
Can anybody suggest me to get this output using a single SQL statement(not using PL/SQL)..
Brayan
|
|
|
|
| Re: Merging multiple rows into single row [message #319541 is a reply to message #319527 ] |
Mon, 12 May 2008 02:26   |
Michel Cadot Messages: 17653 Registered: March 2007 Location: Nanterre, France, http://... |
Senior Member |
|
|
Search for "pivot".
I should point this question is asked several times each week out to you and you should search BEFORE posting.
Regards
Michel
|
|
|
| Re: Merging multiple rows into single row [message #319552 is a reply to message #319527 ] |
Mon, 12 May 2008 03:06   |
Brayan Messages: 276 Registered: November 2004 |
Senior Member |
|
|
Hi Michel,
I did search for PIVOT, but the problem here is I can not use aggregate function for group, becase I need to concatenate he CODE's with a comma separator .
Instead I've done using below query.
SELECT BR,
concatenate_list(CURSOR(SELECT x.CODE FROM src_tel_no x WHERE x.BR = y.BR)) phone_nos
FROM (SELECT DISTINCT BR FROM src_tel_no ) y;
But here it required to create a function. I wanted without any PL/SQL's
Regards,
Brayan
|
|
|
|
|
| Re: Merging multiple rows into single row [message #319857 is a reply to message #319527 ] |
Tue, 13 May 2008 04:11  |
Brayan Messages: 276 Registered: November 2004 |
Senior Member |
|
|
Hi,
Thanks a lot Michel and mshrkshl, it worked for me.
Brayan.
|
|
|