--------------------------------------------------------
--  DDL for View HIERARCHICAL_VERCONSYS_FILTER
--------------------------------------------------------

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "ENVX_OPER"."HIERARCHICAL_VERCONSYS_FILTER" ("LEVEL_ALIAS", "LEVEL_ID", "PARENT_ID", "GROUP_ID", "LEVEL_PATH", "LEVEL_PATH_ID", "LEVEL_ORDER", "LEVEL_NAME", "LEVEL_STATUS", "DESCRIPTION", "LEVEL_REAL_ID") AS 
  SELECT UNIQUE 'T'             AS level_alias,
                 'T' || t.id     AS level_id,
                 NULL            AS parent_id,
                 i.id_marca      AS group_id,
                 '/' || to_char(
                    t.carpeta_repo
                 ) AS level_path,
                 to_char(
                    t.id
                 ) AS level_path_id,
                 0               AS level_order,
                 t.nombre        AS level_name,
                 1               AS level_status,
                 t.nombre        AS description,
                 t.id            AS level_real_id
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM ver_tecnologias    t,
          ver_instancias     i
    WHERE t.id = i.id_tecnologia
   UNION ALL
   SELECT UNIQUE 'M'                        AS level_alias,
                 'M' || m.id                AS level_id,
                 'T' || i.id_tecnologia     AS parent_id,
                 m.id                       AS group_id,
                 '/'
                 || (
                    SELECT carpeta_repo
                      FROM ver_tecnologias t
                     WHERE t.id = i.id_tecnologia
                 )
                 || '/'
                 || m.carpeta_repo AS level_path,
                 to_char(i.id_tecnologia
                         || ','
                         || m.id) AS level_path_id,
                 0                          AS level_order,
                 m.nombre                   AS level_name,
                 1                          AS level_status,
                 m.carpeta_repo             AS description,
                 m.id                       AS level_real_id
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM ver_marcas        m,
          ver_instancias    i
    WHERE m.id = i.id_marca
   UNION ALL
   SELECT 'I'                   AS level_alias,
          'I' || i.id           AS level_id,
          'M' || i.id_marca     AS parent_id,
          i.id_marca            AS group_id,
          '/'
          || t.carpeta_repo
          || '/'
          || (
             SELECT carpeta_repo
               FROM ver_marcas m
              WHERE m.id = i.id_marca
          )
          || '/'
          || i.nombre AS level_path,
          to_char(i.id_tecnologia
                  || ','
                  || i.id_marca
                  || ','
                  || i.id) AS level_path_id,
          0                     AS level_order,
          i.nombre              AS level_name,
          1                     AS level_status,
          i.nombre              AS description,
          i.id                  AS level_real_id
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM ver_tecnologias    t,
          ver_instancias     i
    WHERE t.id = i.id_tecnologia
   UNION ALL
   SELECT 'S'                       AS level_alias,
          'S' || s.id               AS level_id,
          'I' || s.id_instancia     AS parent_id,
          i.id_marca                AS group_id,
          '/'
          || (
             SELECT carpeta_repo
               FROM ver_tecnologias t
              WHERE t.id = i.id_tecnologia
          )
          || '/'
          || (
             SELECT carpeta_repo
               FROM ver_marcas m
              WHERE m.id = i.id_marca
          )
          || '/'
          || i.nombre
          || '/'
          || s.nombre AS level_path,
          to_char(i.id_tecnologia
                  || ','
                  || i.id_marca
                  || ','
                  || i.id
                  || ','
                  || s.id) AS level_path_id,
          0                         AS level_order,
          s.nombre                  AS level_name,
          1                         AS level_status,
          s.nombre                  AS description,
          s.id                      AS level_real_id
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM ver_instancias    i,
          ver_esquemas      s
    WHERE s.id_instancia = i.id
   UNION ALL
   SELECT 'Y'             AS level_alias,
          'Y' || y.id     AS level_id,
          'S' || s.id     AS parent_id,
          i.id_marca      AS group_id,
          '/'
          || (
             SELECT carpeta_repo
               FROM ver_tecnologias t
              WHERE t.id = i.id_tecnologia
          )
          || '/'
          || (
             SELECT carpeta_repo
               FROM ver_marcas m
              WHERE m.id = i.id_marca
          )
          || '/'
          || i.nombre
          || '/'
          || s.nombre
          || '/'
          || y.nombre AS level_path,
          to_char(i.id_tecnologia
                  || ','
                  || i.id_marca
                  || ','
                  || i.id
                  || ','
                  || s.id
                  || ','
                  || y.id) AS level_path_id,
          0               AS level_order,
          y.nombre        AS level_name,
          1               AS level_status,
          y.nombre        AS description,
          y.id            AS level_real_id
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM ver_instancias      i,
          ver_esquemas        s,
          ver_tipos_objeto    y
    WHERE s.id_instancia = i.id
      AND i.id_marca         = y.id_marca
      AND i.id_tecnologia    = y.id_tecnologia
;
