Oracle文档中有这么一段解释:
The manner in which Oracle processes a WHERE clause (if any) in a hierarchical
query depends on whether the WHERE clause contains a join:
If the WHERE predicate contains a join, Oracle applies the join predicates before
doing the CONNECT BY processing.
Oracle applies any non-join predicates (that is, all predicates if the WHERE clause
does not contain a join) after doing the CONNECT BY processing without
affecting the other rows of the hierarchy.谁能给具体解释一下,最好附上实例。多谢!

解决方案 »

  1.   


    SELECT LPAD(' ', 2 * (LEVEL - 1), '-') || ENAME P,
           EMPNO,
           MGR,
           JOB,
           SAL,
           LEVEL
      FROM scott.emp 
     WHERE sal>2000
     START WITH MGR IS NULL
    CONNECT BY PRIOR EMPNO = MGR;
    等价于下面的sql:
    SELECT LPAD(' ', 2 * (LEVEL - 1), '-') || ENAME P,
           EMPNO,
           MGR,
           JOB,
           SAL,
           LEVEL
      FROM (SELECT * FROM scott.emp WHERE sal>2000) 
     START WITH MGR IS NULL
    CONNECT BY PRIOR EMPNO = MGR;---------------------------------------
    SELECT LPAD(' ', 2 * (LEVEL - 1), '-') || ENAME P,
           EMPNO,
           MGR,
           JOB,
           SAL,
           LEVEL
      FROM  scott.emp 
     WHERE empno>7800 
     START WITH MGR IS NULL
    CONNECT BY PRIOR EMPNO = MGR;
    等价于:
    SELECT *
      FROM (SELECT LPAD(' ', 2 * (LEVEL - 1), '-') || ENAME P,
                   EMPNO,
                   MGR,
                   JOB,
                   SAL,
                   LEVEL
              FROM SCOTT.EMP
             START WITH MGR IS NULL
            CONNECT BY PRIOR EMPNO = MGR)
     WHERE EMPNO > 7800;