계층형쿼리(오라클) / ROWNUM을 이용한 접근

in sql •  6 years ago  (edited)

계층형 쿼리

SELECT *

FROM ORCL_BRD_RPL

START WITH BRD_PNO = 0 -- 시작행

CONNECT BY PRIOR BRD_NO = BRD_PNO -- 연결

ORDER SIBLINGS BY BRD_NO DESC; -- 정렬순서

계층형 쿼리를 ROWNUM을 이용하여 순서로 접근해서 찾아오는 방법

SELECT *

FROM (SELECT ROWNUM AS RNUM, E.*

    FROM ( SELECT *

            FROM ORCL_BRD_RPL

            START WITH BRD_PNO = 0  -- 시작행

            CONNECT BY PRIOR BRD_NO = BRD_PNO   -- 연결

            ORDER SIBLINGS BY BRD_NO DESC) E)

WHERE RNUM BETWEEN 3 AND 6;

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!