oracle 父子节点 查询
1)从父节点到所有子节点
SELECT t.ID id,
RPAD( '- ', 8*(LEVEL-1), ' -' ) || l.MEANING name,
t.MENU_BAR_ID menuBraId,
t.PARENT_ID parentId,
t.DISPLAY_ORDER displayOrder,
CONNECT_BY_ROOT NAME ROOT,
CONNECT_BY_ISLEAF ISLEAF,
LEVEL,
SYS_CONNECT_BY_PATH(NAME, '<') path
FROM MENU_ITEM t, LANGUAGEPACKAGE l
where t.TITLE_ID=l.ID and l.LANGUAGE='en_US'
START WITH t.ID='1' or t.ID='2' or t.ID='3' or t.ID='4' or t.ID='5'
CONNECT BY PRIOR t.ID=t.PARENT_ID
查询menu_ITEM下id是1,2,3,4,5下的所有节点。节点关系是: menu_ITEM对应的PARENT_ID是menu_ITEM的id。
1)从子节点到所有该子节点上的所有父节点
SELECT t.ID id,
RPAD( '- ', 8*(LEVEL-1), ' -' ) || l.MEANING name,
t.MENU_BAR_ID menuBraId,
t.PARENT_ID parentId,
t.DISPLAY_ORDER displayOrder,
CONNECT_BY_ROOT NAME ROOT,
CONNECT_BY_ISLEAF ISLEAF,
LEVEL,
SYS_CONNECT_BY_PATH(NAME, '<') path
FROM MENU_ITEM t, LANGUAGEPACKAGE l
where t.TITLE_ID=l.ID and l.LANGUAGE='en_US'
START WITH t.ID='141'
CONNECT BY PRIOR t.PARENT_ID=t.ID
查询menu_ITEM下id是141的所有父节点。
上面两段脚本的区别在于:
第一个: CONNECT BY PRIOR t.ID=t.PARENT_ID
第二个: CONNECT BY PRIOR t.PARENT_ID=t.ID