Please solve my issue [message #624272] |
Sat, 20 September 2014 00:45 |
|
aaditya321
Messages: 225 Registered: January 2014 Location: Delhi
|
Senior Member |
|
|
Please give me the solution
I have a table like this
SQL> craete table test(id number(3), Name varchar2(30));
Table created.
SQL> insert into test values(1, 'a');
1 row created.
SQL> insert into test values(1, 'b');
1 row created.
SQL> insert into test values(1, 'b');
1 row created.
SQL> insert into test values(2, 'd');
1 row created.
SQL> insert into test values(2, 'e');
1 row created.
SQL> insert into test values(3, 'f');
1 row created.
SQL> insert into test values(4, 'g');
1 row created.
SQL> Select id, name from test;
Id Name
1 a
1 b
1 c
2 d
2 e
3 f
4 g
I want output like this
Id Name
1 a, b, c
2 d, e
3 f
4 g
|
|
|
|
|
|
Re: Please solve my issue [message #624280 is a reply to message #624279] |
Sat, 20 September 2014 02:13 |
jimit_shaili
Messages: 237 Registered: June 2006 Location: India, Ahmedabad
|
Senior Member |
|
|
Dear Aditya,
Following will sovle your problem.
select id,listagg(name,',') within group(order by id) test_str from test group by id;
ID TEST_STR
--- ----------
1 a,b,c
2 d,e
3 f
4 g
Regards
Jimit
|
|
|
|
|
|
Re: Please solve my issue [message #624304 is a reply to message #624283] |
Sat, 20 September 2014 09:44 |
anil_mk
Messages: 146 Registered: August 2006 Location: Bangalore, India
|
Senior Member |
|
|
Use below query
with tab as (select 1 as id , 'a' as name from dual union
select 1 as id , 'b' as name from dual union
select 1 as id , 'c' as name from dual union
select 2 as id , 'e' as name from dual union
select 2 as id , 'e' as name from dual union
select 3 as id , 'f' as name from dual union
select 4 as id , 'g' as name from dual )
select ID, wm_concat(name) name from tab GROUP BY ID;
Thanks,
Anil
|
|
|
|
|
|
|
Re: Please solve my issue [message #624309 is a reply to message #624308] |
Sat, 20 September 2014 10:38 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
anil_mk wrote on Sat, 20 September 2014 21:02I have used wm_concat in Oracle 10g as well.
If you did that in PRODUCTION, then immediately consult your manager and tell him honestly. And if some problem happens in production, then say this to yourself "R.I.P. my database". Since Oracle won't support at all.
Good luck!
|
|
|
|
Re: Please solve my issue [message #624311 is a reply to message #624310] |
Sat, 20 September 2014 11:28 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Look, I am not trying to irritate you, but, my intention was to make you aware of the consequences.
If you have nothing to do with Production code, why do you waste time over undocumented features? That too when it was already told to you about it.
|
|
|
Re: Please solve my issue [message #624312 is a reply to message #624311] |
Sat, 20 September 2014 12:00 |
anil_mk
Messages: 146 Registered: August 2006 Location: Bangalore, India
|
Senior Member |
|
|
Lalit, I have commented first time on undocumented feature, yes it was my mistake.
Aaditya,
Please use below
with tab as (select 1 as id , 'a' as name from dual union
select 1 as id , 'b' as name from dual union
select 1 as id , 'c' as name from dual union
select 2 as id , 'e' as name from dual union
select 2 as id , 'e' as name from dual union
select 3 as id , 'f' as name from dual union
select 4 as id , 'g' as name from dual )
select id,
replace(ltrim(sys_connect_by_path(name,'|'),'|'),'|',', ') name
from (
select id,
name,
row_number() over(partition by id order by name) rn
from tab
)
where connect_by_isleaf = 1
start with rn = 1
connect by id = prior id
and rn = prior rn + 1
order by id;
Id Name
------------------------------------
1 a, b, c
2 e
3 f
4 g
[Updated on: Sat, 20 September 2014 12:03] Report message to a moderator
|
|
|
Re: Please solve my issue [message #624314 is a reply to message #624312] |
Sat, 20 September 2014 12:21 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
It was Aaditya's work, we ALL know how to do it; why don't you let him find it by himself?
You think you helped him, you didn't.
Tell me and I'll forget; show me and I may remember; involve me and I'll understand.
[Updated on: Sat, 20 September 2014 12:22] Report message to a moderator
|
|
|
|
Re: Please solve my issue [message #624431 is a reply to message #624308] |
Mon, 22 September 2014 13:06 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
anil_mk wrote on Sat, 20 September 2014 11:32I have used wm_concat in Oracle 10g as well.
Sure you can use it, but you are in "Swim at your own risk - no lifeguard on site" situation.
"Lifeguard" (Oracle support) says:
Quote:The function WMSYS.WM_CONCAT is an internal undocumented function which is installed/uninstalled as part of the Workspace Manager feature of Oracle Database. It is internally used in a number of Workspace Manager views. It is not meant to be used by customers directly, and could be changed/updated without notice by Oracle Development. Do not use the WMSYS.WM_CONCAT view in your application.
Read:
WMSYS.WM_CONCAT Should Not Be Used For Customer Applications, It Is An Internal Function [ID 1336219.1]
Problem with WMSYS.WM_CONCAT Function after Upgrading [ID 1300595.1]
SY.
|
|
|