以下查询(请参阅SQL Fiddle)将为您提供其根处于活动状态的所有活动节点:
SELECT *
FROM (
SELECT c.*,
PRIOR c.ACTIVE AS PARENT_ACTIVE,
CONNECT_BY_ROOT(c.CATEGORY_NAME) AS CATEGORY_ROOT_NAME,
CONNECT_BY_ROOT(c.ACTIVE) AS ROOT_ACTIVE
FROM CATEGORY c
WHERE c.ACTIVE = 'TRUE'
START WITH c.CATEGORY_PARENT_NAME IS NULL
CONNECT BY c.CATEGORY_PARENT_NAME = PRIOR c.CATEGORY_NAME
ORDER SIBLINGS BY c.MENU_INDEX
) a
WHERE a.ROOT_ACTIVE = 'TRUE'
要进一步过滤您的结果以仅包括其父节点、祖父节点和直到层次结构根的所有祖先节点都处于活动状态的活动节点(请参阅SQL Fiddle):
SELECT *
FROM (
SELECT c.*,
PRIOR c.ACTIVE AS PARENT_ACTIVE,
CONNECT_BY_ROOT(c.CATEGORY_NAME) AS CATEGORY_ROOT_NAME,
CONNECT_BY_ROOT(c.ACTIVE) AS ROOT_ACTIVE,
SYS_CONNECT_BY_PATH(c.ACTIVE, '/') AS ACTIVE_PATH
FROM CATEGORY c
WHERE c.ACTIVE = 'TRUE'
START WITH c.CATEGORY_PARENT_NAME IS NULL
CONNECT BY c.CATEGORY_PARENT_NAME = PRIOR c.CATEGORY_NAME
ORDER SIBLINGS BY c.MENU_INDEX
) a
WHERE a.ROOT_ACTIVE = 'TRUE'
AND a.ACTIVE_PATH NOT LIKE '%FALSE%'
提示