次のクエリ ( 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%'
チップ