Search code examples
sqloracle-databaseoracle10gsql-order-byora-00907

Oracle 10g : ORDER SIBLINGS inside a VIEW


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


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;