The clauses in hierarchical queries are processed in the following order.
- join conditions (either in the FROM clause or the WHERE clause)
- START WITH clause
- CONNECT BY clause
- WHERE clause conditions that are not joins.
The following two snippets demonstrate how this order of operations affects query results when filter conditions are in the WHERE clause versus when they are in the CONNECT BY clause.
Filter Condition in WHERE |
Filter Condition in CONNECT BY |
|---|---|
select
lpad(' ', level-1 ) ||
key as key_indented ,
level
from
t
WHERE
LEVEL != 3
start with
key = 'server'
connect by
parent_key = prior key
--
;
KEY_INDENTED LEVEL --------------- ------ server 1 bin 2 config 2 ctx 2 delx 4 enlx 4 eslx 4 |
select
lpad(' ', level-1 ) ||
key as key_indented ,
level
from
t
--
--
start with
key = 'server'
CONNECT BY
parent_key = prior key and
LEVEL != 3
;
KEY_INDENTED LEVEL --------------- ------ server 1 bin 2 config 2 ctx 2 |
