-------------------------------------------------------------------------------------------

PIVOT 

-------------------------------------------------------------------------------------------


WITH TEMP01 AS

(

SELECT '2014' AS YEAR, 1 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 2 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 3 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 4 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 5 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 6 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 7 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 8 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 9 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 10 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 11 AS MONTH FROM DUAL

UNION ALL

SELECT '2014' AS YEAR, 12 AS MONTH FROM DUAL

UNION ALL

SELECT '2015' AS YEAR, 8 AS MONTH FROM DUAL

UNION ALL

SELECT '2015' AS YEAR, 9 AS MONTH FROM DUAL

UNION ALL

SELECT '2016' AS YEAR, 10 AS MONTH FROM DUAL

UNION ALL

SELECT '2017' AS YEAR, 11 AS MONTH FROM DUAL

UNION ALL

SELECT '2018' AS YEAR, 12 AS MONTH FROM DUAL

)

SELECT *

  FROM TEMP01

 PIVOT ( MAX(MONTH)

         FOR MONTH IN (1 AS M1,2 AS M2,3 AS M3,4 AS M4,5 AS M5,6 AS M6,7 AS M7,8 AS M8,9 AS M9,10 AS M10,11 AS M11,12 AS M12)

       );




-------------------------------------------------------------------------------------------

LISTAGG 

-------------------------------------------------------------------------------------------


SELECT a.c1,

LISTAGG (a.c2, ',') WITHIN GROUP (ORDER BY a.c2) AS c2

 FROM t1 a

GROUP BY a.c1;

 C1 C2          
--- ------------
  1 01          
  2 02,03       
  3 04,04,05,06 


'ORACLE > SQL' 카테고리의 다른 글

윈도우 함수(WINDOW FUNCTION)  (0) 2018.11.01
PLSQL - 다차원 콜렉션  (0) 2018.01.24
BULK COLLECT  (0) 2017.08.17
오라클 정규식 사용 팁  (0) 2017.07.07
잡동사니 퀴리  (0) 2017.07.05

+ Recent posts