Order Siblings By not correct at root level
426078Aug 13 2004 — edited Aug 13 2004I tried to reproduce this problem in the SCOTT/TIGER schema, but apprently it is more complicated.
The trouble I have is that I have a hierarchical query which has an ORDER SIBLINGS BY clause. The query is expected to return a forest of trees (i.e. multiple records match the START WITH clause. I expect that these records will be sorted by the ORDER SIBLINGS BY clause, but in my case that does not happen.
Here is a slightly simplified form of my query:
SELECT A.id as ID,
LEVEL AS LVL,
ROWNUM AS ROW,
SRAM.GroupOrder AS GRP, SRAM.AccountOrder AS ACT
FROM
Account A
LEFT OUTER JOIN SheetRootAccountMap SRAM ON (SRAM.SheetID = 41 AND SRAM.AccountID = A.ID AND SRAM.SheetInstanceID = 161)
START WITH A.id IN (183,163,179,187,167)
CONNECT BY PRIOR A.id = A.parentid
ORDER SIBLINGS BY SRAM.GroupOrder, SRAM.AccountOrder, A.Orderval
Accounts are hierarchical (some are root level, others have parents).
SheetRootAccountMap is a map table that associates Sheets and root level accounts.
The goal of the query is to return the correct sort order.
When I run this query, I get back:
ID LVL ROW GRP ACT
183 1 1 1 2
179 1 2 4 5
187 1 3 6 7
163 1 4 1 3
167 1 5 6 8
The GRP (fourth column) should be ascending (note that in this case all of the returned records are roots, so the level is always 1).