Oracle: Transformar linhas em colunas
É usada uma view para simplificar a ilustração.
CREATE VIEW MYSCHEMA.MYVIEW
AS
SELECT 11 COL0, 37 AS COL1,78 AS COL2,107 AS COL3,163 AS COL4,206 AS COL5,209 AS COL6,44 AS COL7 FROM DUAL
UNION ALL
SELECT 12, 201008,201005,201006,201007,201009,201010,201011 FROM DUAL
SELECT
DECODE(UNPIVOT_ROW, 1, COL1,
2, COL2,
3, COL3,
4, COL4,
5, COL5,
6, COL6,
7, COL7) AS COLX
FROM MYSCHEMA.MYVIEW,
(SELECT LEVEL AS UNPIVOT_ROW FROM DUAL CONNECT BY LEVEL <= 7)
Licença CC BY-SA 4.0
Silvia Pinhão Lopes, 7.1.17
Sem comentários: