| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Nother sql question...
Steven,
I know your post is old, but I didn't see any responses, so I thought I'd propose the following:
SELECT SUBSTR(string,2)
FROM (
SELECT SYS_CONNECT_BY_PATH(name,',') string
FROM (
SELECT name
, LAG(name) OVER (ORDER BY name) prior_name
FROM (
SELECT DISTINCT name
FROM tableA
WHERE id IN (<your list of distinct ID values>)
)
)
START WITH prior_name IS NULL
CONNECT BY PRIOR name = prior_name
ORDER BY 1 DESC
)
/* * Output */
SUBSTR(STRING,2)
Myths Resolved: "A eye for eye, tooth for tooth, ... (Ex. 21:24) is normally quoted as justification for revenge. On the contrary, it was commanded to stop people from taking greater revenge than the original injustice."
> -----Original Message-----
> From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org]
> On Behalf Of Stephens, Chris
> Sent: Wednesday, November 10, 2004 1:21 PM
> To: oracle-l_at_freelists.org
> Subject: Nother sql question...
>
>
> I have a list of id's passed in. I need a string of names returned that
> coincide with those id's. It's very easy to just create a cursor, loop
> through, and concantenate to the string on every iteration but I was
> thinking there would be a way to do this in sql with one of the new
> analytic functions but nothing is really jumping out at me.
>
> Anyone?
>
> tableA
> Id Name
> 1 A
> 2 B
> 3 C
>
> Sql>fReturnString(1,2,3);
> Sql>a,b,c
>
>
> --
> http://www.freelists.org/webpage/oracle-l
-- http://www.freelists.org/webpage/oracle-lReceived on Thu Mar 03 2005 - 13:44:21 CST
![]() |
![]() |