ORACLE 根据根节点查所有上层节点
1.基本数据
SELECT * FROM TABLE_MUEN T
ID CODE NAME PARENTCODE
0 FIRST-SBZHYW 社保综合 ROOT
1 SECOND-SBZHYW-ZZYW 自助业务 FIRST-SBZHYW
2 THIRD-SBZHYW-YWCXYDY 业务查询与打印 SECOND-SBZHYW-ZZYW
3 FOUR-SBZHYW-GRCBZMDY 个人参保证明打印 THIRD-SBZHYW-YWCXYDY
2.SQL
SELECT CONNECT_BY_ROOT(ID),
CONNECT_BY_ROOT(T.CODE) CODE,
CONNECT_BY_ROOT(T.NAME) NAME,
CONNECT_BY_ROOT(T.PARENTCODE) PARENTCODE
FROM TABLE_MUEN T
WHERE T.CODE = 'FOUR-SBZHYW-GRCBZMDY'
CONNECT BY PRIOR T.CODE = T.PARENTCODE