Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Comma separate in the group by query result

JameSep 5 2014 — edited Sep 5 2014

Dear All,

Kindly provide your suggestions to get the below explained requirement in a select query.    

Scripts:-

Create Table Comma_Sep

(Id Number,

Name Varchar2(20),

City Varchar2(20),

Country Varchar2(20));

REM INSERTING into COMMA_SEP

Set Define Off;

Insert Into Comma_Sep (Id,Name,City,Country) Values (101,'Aron','California','US');

Insert Into Comma_Sep (Id,Name,City,Country) Values (102,'Mark','California','US');

Insert Into Comma_Sep (Id,Name,City,Country) Values (103,'Dany','Florida','US');

Insert Into Comma_Sep (Id,Name,City,Country) Values (104,'John','Cambridge','UK');

Insert Into Comma_Sep (Id,Name,City,Country) Values (105,'John','Bristol','UK');

Insert Into Comma_Sep (Id,Name,City,Country) Values (106,'Jeff','Bhauri','Saudi');

select country,name from comma_sep

group by country,name

order by country;

COUNTRY              NAME              

-------------------- --------------------

Saudi                Jeff                

UK                   John                

US                   Aron                

US                   Dany                

US                   Mark  

Expected Query Result:-

COUNTRY              NAME              

-------------------- --------------------

Saudi                Jeff                

UK                   John                

US                   Aron,Dany,Mark

I want to display the name values in a comma separated list for each country if it has more than one person.

Please do the needful

Regards,

Jame

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2014
Added on Sep 5 2014
3 comments
1,644 views