RE: workaround for odciaggregate bug?
Date: Tue, 27 Jan 2009 14:27:04 -0500
Thanks. Your query does the trick.
And, true, it doesn't make sense to expect the row ordering to work - especially since ODCIAggregate seems to have been targeted at numeric aggregation.
Thanks to Ian, Mark, and Charles for your help, too.
From: Stephane Faroult [mailto:sfaroult_at_roughsea.com] Sent: Friday, January 23, 2009 17:26
To: Stauffer, Robert G
Subject: Re: workaround for odciaggregate bug?
I'm not sure it really qualifies as a bug, because row ordering is
something that has no meaning in the relational theory, and therefore
Oracle is free to return rows in whichever order it wants - only the
final "order by" counts.
But there is another solution than stringAgg, and this one works "by design":
SQL> select acctnbr,
2 replace(path, '|', '') result 3 from (select acctnbr,
4 sys_connect_by_path(prodcount, '|') path, 5 rn, 6 cnt 7 from (select acctnbr, 8 prodcount, 9 row_number() over (partition by acctnbr 10 order by snapshotdate) rn, 11 count(snapshotdate) over (partition by acctnbr) cnt 12 from testtable) 13 connect by acctnbr = prior acctnbr 14 and rn = 1 + prior rn 15 start with rn = 1)
16 where rn = cnt
17 order by acctnbr
HTH S. Faroult
Stauffer, Robert G wrote:
> 22.214.171.124 and 10.1.0.4 on AIX 5.2
> I'm trying to use ODCIAggregate and Tom Kyte's stringAgg function to
> concatenate a number in multiple rows into a string. Below is the
> output of the select statements I ran. Create scripts for the table,
> type, and function are below the output. I'm expecting the returned
> string to be '010203' but it returns '010032'. Unfortunately, it
> like there's a bug (7194959 to be fixed in 11.2) in ODCIAggregate that
> "unsorts" the sorted data when it creates the concatenated string.
> looked around (asktom, metalink, etc.) and can't seem to find a
> work-around for this method. Has anyone come up with one?
This e-mail message and any files transmitted with it are intended for the use of the individual or entity to which they are addressed and may contain information that is privileged, proprietary and confidential. If you are not the intended recipient, you may not use, copy or disclose to anyone the message or any information contained in the message. If you have received this communication in error, please notify the sender and delete this e-mail message. The contents do not represent the opinion of D&E except to the extent that it relates to their official business.