SELECT D.SETID, D.TREE_NODE AS DEPTID, D.EFFDT, D.EFF_STATUS, D.DESCR, D.DESCRSHORT, LTRIM(SYS_CONNECT_BY_PATH(D.DESCR, '>'), '>') FULL_DESCR FROM (SELECT D.SETID, D.TREE_NODE, D.PARENT_NODE_NAME, P.EFFDT, P.EFF_STATUS, P.DESCR, P.DESCRSHORT FROM PSTREENODE D, PSTREEDEFN T, PS_DEPT_TBL P WHERE T.TREE_NAME ='DEPT_SECURITY' AND T.SETID ='NH001' AND T.EFFDT = (SELECTMAX(T_ED.EFFDT) FROM PSTREEDEFN T_ED WHERE T_ED.SETID = T.SETID AND T_ED.SETCNTRLVALUE = T.SETCNTRLVALUE AND T_ED.TREE_NAME = T.TREE_NAME AND T_ED.EFFDT <= SYSDATE) AND D.SETID = T.SETID AND D.TREE_NAME = T.TREE_NAME AND D.SETCNTRLVALUE = T.SETCNTRLVALUE AND D.EFFDT = T.EFFDT AND T.EFF_STATUS ='A' AND P.SETID = D.SETID AND P.DEPTID = D.TREE_NODE AND P.EFFDT = (SELECTMAX(P1.EFFDT) FROM PS_DEPT_TBL P1 WHERE P1.DEPTID = P.DEPTID AND P1.SETID = P.SETID AND P1.EFFDT <= SYSDATE)) D STARTWITH D.PARENT_NODE_NAME =' ' CONNECTBY NOCYCLE PRIOR D.TREE_NODE = D.PARENT_NODE_NAME
SELECT D.SETID, D.TREE_NODE AS DEPTID, D.EFFDT, D.EFF_STATUS, D.DESCR, D.DESCRSHORT, LTRIM(SYS_CONNECT_BY_PATH(D.DESCR, '>'), '>') FULL_DESCR FROM (SELECT D.SETID, D.TREE_NODE, D.PARENT_NODE_NAME, P.EFFDT, P.EFF_STATUS, P.DESCR, P.DESCRSHORT FROM PSTREENODE D, PSTREEDEFN T, PS_DEPT_TBL P WHERE T.TREE_NAME ='DEPT_SECURITY' AND T.SETID ='NH001' AND T.EFFDT = (SELECTMAX(T_ED.EFFDT) FROM PSTREEDEFN T_ED WHERE T_ED.SETID = T.SETID AND T_ED.SETCNTRLVALUE = T.SETCNTRLVALUE AND T_ED.TREE_NAME = T.TREE_NAME AND T_ED.EFFDT <= SYSDATE) AND D.SETID = T.SETID AND D.TREE_NAME = T.TREE_NAME AND D.SETCNTRLVALUE = T.SETCNTRLVALUE AND D.EFFDT = T.EFFDT AND T.EFF_STATUS ='A' AND P.SETID = D.SETID AND P.DEPTID = D.TREE_NODE AND P.EFFDT = (SELECTMAX(P1.EFFDT) FROM PS_DEPT_TBL P1 WHERE P1.DEPTID = P.DEPTID AND P1.SETID = P.SETID AND P1.EFFDT <= SYSDATE)) D STARTWITH D.TREE_NODE ='1000003341' CONNECTBY NOCYCLE D.TREE_NODE = PRIOR D.PARENT_NODE_NAME