여러행을 하나의 컬럼으로 합치기

 

--Oracle version : 11g
SELECT LISTAGG(CODE, ',') WITHIN GROUP(ORDER BY CODE DESC) AS PLUS_COLUMN 
  FROM COM_CODE
WHERE ROWNUM < 5;

 

--Oracle version : 10g
SELECT WM_CONCAT(CODE) AS PLUS_COLUMN
  FROM COM_CODE
WHERE ROWNUM < 5;

 

--Oracle version : 9i
SELECT SUBSTR(XMLAGG(XMLELEMENT(X, ',', CODE) ORDER BY CODE).EXTRACT('//text()'), 2) AS PLUS_COLUMN
  FROM COM_CODE
WHERE ROWNUM < 5;

 

반응형

+ Recent posts