Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Dinamizar várias tabelas com valores padrão


Esta consulta pode ser um bom começo como base para outras experiências:
With src As (
    SELECT  lmnt.element_name
        ,   lmnt.element_entry_id
        ,   nval.input_value_id
        ,   nval.screen_entry_value
--        ,   eval.name 
        ,   row_number() over (partition by lmnt.element_name, lmnt.element_entry_id
                               order by lmnt.element_name  ) rn
    FROM    XX_SAMPLE_ELEMENTS lmnt
        ,   XX_ENTRY_VALUES    nval
        ,   XX_ELEMENT_VALUES  eval
    where   lmnt.element_entry_id = nval.element_entry_id
    and     eval.INPUT_VALUE_ID = nval.INPUT_VALUE_ID          
    order by lmnt.element_name
)


SELECT * FROM src
PIVOT (
    max( input_value_id ) As input_value,
    min( screen_entry_value ) as screen_entry_value
    FOR (rn)
    IN (1,2,3,4,5)
)