Pages

Wednesday, November 21, 2012

To the hashcode() and equals() problem


Oracle connect by prior with order siblings

To not forget:


with hier as (
  select 'Foo' as name, 1 as id, null as pid from dual union all
  select 'FooBar', 2, 1 from dual union all
  select 'Bar', 3, null from dual union all
  select 'BarFoo', 4, 3 from dual union all
  select 'FooZo', 5, 1 from dual union all
  select 'FooBarFoo', 6, 2 from dual union all
  select 'FooZoo', 7, 1 from dual union all
  select 'FooZooo', 8, 1 from dual
)
select LPAD(' ', 2*(LEVEL-1))||name
from hier
start with pid is null
connect by prior id=pid
order siblings by id;