Files
oper/DB/VIEWS/REVERSE_HIERARCHICAL_VERCONSYS.sql

50 lines
1.2 KiB
MySQL
Raw Normal View History

2023-06-08 11:55:59 -03:00
--------------------------------------------------------
-- DDL for View REVERSE_HIERARCHICAL_VERCONSYS
--------------------------------------------------------
CREATE OR REPLACE FORCE EDITIONABLE VIEW "ENVX_OPER"."REVERSE_HIERARCHICAL_VERCONSYS" ("ID", "PARENT_ID", "level", "NAME", "PATH") AS
SELECT id,
(
CASE
WHEN level = 1 THEN
NULL
ELSE
regexp_substr(
sys_connect_by_path(
id,
'/'
),
'[^\/]+',
1,
level - 1
)
END
) AS parent_id,
level as "level",
regexp_substr(
level_path,
'[^\/]+',
1,
level
) AS name,
level_path AS path
FROM (
SELECT ROW_NUMBER()
OVER(
ORDER BY level_path
) as id,
level_path,
regexp_replace(
level_path,
'\/[^\/]+$',
''
) AS parent_path
FROM hierarchical_verconsys_filter
) h
START WITH
parent_path IS NULL
CONNECT BY
PRIOR level_path = parent_path
ORDER BY level_path
;