계층형 테이블이 아래와 같이 존재하는데 검색조건으로 DISP_CAT_NO를 사용하여 최상위 CAT_LVL_DPTH = 1인 DISP_CAT_NO를 찾는 쿼리를 만들고 싶은데 잘 안되어 질문드려봅니다
컬럼정의 : DISP_CAT_NO = 카테고리번호, PRNT_CAT_NO = 상위카테고리번호, CAT_LVL_DPTH = 카테고리 레벨
WITH SEARCH_INFO AS ( SELECT '100100001' AS DISP_CAT_NO, '0' AS PRNT_CAT_NO, '1' AS CAT_LVL_DPTH FROM DUAL UNION ALL SELECT '100100002' AS DISP_CAT_NO, '100100001' AS PRNT_CAT_NO, '2' AS CAT_LVL_DPTH FROM DUAL UNION ALL SELECT '100100003' AS DISP_CAT_NO, '100100002' AS PRNT_CAT_NO, '3' AS CAT_LVL_DPTH FROM DUAL ) SELECT * FROM SEARCH_INFO;
WITH search_info AS ( SELECT '100100001' disp_cat_no, '0' prnt_cat_no, 1 cat_lvl_dpth FROM dual UNION ALL SELECT '100100002', '100100001', 2 FROM dual UNION ALL SELECT '100100003', '100100002', 3 FROM dual ) SELECT * FROM search_info WHERE CONNECT_BY_ISLEAF = 1 START WITH disp_cat_no = :v_disp_cat_no CONNECT BY PRIOR prnt_cat_no = disp_cat_no ;