Question

Is it possible to add a ORDER SIBLINGS BY fieldName inside a view? I've got a hierarchical structure, in which I'm successfully using a query with the CONNECT BY feature.

However, when I add the ORDER SIBLINGS BY fieldName inside the view definition, Oracle gives a strange parenthesis error.

drop view myview;
create view myview as (
select id, level as depth, label, parentid, orderhint, 
       connect_by_root myfield1 "myfield1", connect_by_root id "toplevelparentid"
  from mytable
  connect by prior id = parentid
  start with id in (select id from mytable where parentid is null)
  order siblings by orderhint
);

Without the ORDER SIBLINGS BY or outside a view definition it works like a charm. Otherwise, I get:

ORA-00907: Missing right parenthesis

Was it helpful?

Solution

Have you tried removing your parentheses:

drop view myview;
create view myview as
select id, level as depth, label, parentid, orderhint, 
connect_by_root myfield1 "myfield1", connect_by_root id "toplevelparentid"
from mytable
connect by prior id = parentid
start with id in (select id from mytable where parentid is null)
order siblings by orderhint;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top