Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Rows to a List
I have a many to one relationship where I'd like to convert the rows to
a list format.
I currently use a function, but using that function slows the query down.
I'd like to improve on that performance.
example schema:
tbl_x: num,flda,fldb,fldc as 1, me, you, them 2, me, you, them 3, me, you, them
tbl_y: num,fldz as
1, fred 1, lisa 1, dave
My function is:
create or replace function list ( field1 number )
return varchar2 as
res varchar2(2000) := null;
first boolean := true;
begin
for curs in
(select fldz from tbl_y where num=field1 order by fldz) loop
if not first then res := res || ','; else first := false; end if; res := res || curs.fldz;
My sql then is:
select num,flda,fldb,fldc,list(num)
from tbl_a
I should get:
'1', 'me', 'you', 'them', 'fred,lisa,dave'
Any ideas to reduce performance?
Thanks, Mike Received on Wed Aug 03 2005 - 12:21:49 CDT
![]() |
![]() |