Q
Problem solve Get help with specific problems with your technologies, process and projects.

Concatenate values separated with commas

I have a query that retrieves around 10 records. I have a task to concatenate the values separated with ','. I would like to know if Oracle has any function that could do that.

I have a query like this:
select userid from users where usergrp='1'
This query retrieves around 10 records. I have a task to concatenate the values separated with ','. I would like to know if Oracle has any function that could do that.
No, you will need to write a user-defined function with a VARRAY or DECODE for this. Something like this might work:
create or replace function    concat( cur sys_refcursor )return    varchar2 
is   retval varchar2(32767);    hold   varchar2(80);begin   loop      fetch 
cur into tmp;      exit when cur%notfound;        ret := ret || ',' || hold; 
end loop;  return retval;end;/ select distinct     substr 
(concat(       cursor(        select userid from users outer where e.usergrp 
= outer.usergrp        )    ),1,40) useridsfrom users e;

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close