sexta-feira, 15 de maio de 2015

Converter Arquivo de Pai Filho em Níveis Hierárquicos




Pessoal bom dia,

Uma das dificuldades que encontrei muitas vezes é de poder transformar arquivos de metadados ou dimensões extraídas do Hyperion, em um formato de níveis. Essa necessidade vem da premissa de carregar dimensões para ferramentas de BI.

Veja extração abaixo em tabela Oracle.  




Tabela convertida


Query que converte:

select
regexp_substr(path,'[^:]+',1,2) CONTA_NIVEL_1,
regexp_substr(path,'[^:]+',1,3) CONTA_NIVEL_2,
regexp_substr(path,'[^:]+',1,4) CONTA_NIVEL_3,
regexp_substr(path,'[^:]+',1,5) CONTA_NIVEL_4,
regexp_substr(path,'[^:]+',1,6) CONTA_NIVEL_5,
regexp_substr(path,'[^:]+',1,7) CONTA_NIVEL_6,
regexp_substr(path,'[^:]+',1,8) CONTA_NIVEL_7,
regexp_substr(path,'[^:]+',1,9) CONTA_NIVEL_8
from
(select level lvl,connect_by_root parent root
                       ,connect_by_root parent || sys_connect_by_path(child,':') path
                 from hyp_stage.t_p_c
                 where connect_by_isleaf = 1
                 start with parent in (select parent
                                         from hyp_stage.t_p_c d
                                        where not exists(select null
                                                           from hyp_stage.t_p_c
                                                          where child = d.parent
                                                        )
                                      )
                connect by prior child = parent
                order by LVL);


Nenhum comentário:

Postar um comentário