WITH 테이블(이름) AS( SELECT '홍길동1' FROM DUAL UNION ALL SELECT '홍길동2' FROM DUAL UNION ALL SELECT '홍길동3' FROM DUAL UNION ALL SELECT '홍길동4' FROM DUAL UNION ALL SELECT '홍길동5' FROM DUAL UNION ALL SELECT '홍길동6' FROM DUAL UNION ALL SELECT '홍길동7' FROM DUAL ) SELECT MAX(DECODE(MOD(ROWNUM,5), 1, 이름)) 이름1 , MAX(DECODE(MOD(ROWNUM,5), 2, 이름)) 이름2 , MAX(DECODE(MOD(ROWNUM,5), 3, 이름)) 이름3 , MAX(DECODE(MOD(ROWNUM,5), 4, 이름)) 이름4 , MAX(DECODE(MOD(ROWNUM,5), 0, 이름)) 이름5 FROM 테이블 GROUP BY TRUNC((ROWNUM-1)/5) ORDER BY TRUNC((ROWNUM-1)/5) ;
WITH t(nm) AS( SELECT '홍길동1' FROM DUAL UNION ALL SELECT '홍길동2' FROM DUAL UNION ALL SELECT '홍길동3' FROM DUAL UNION ALL SELECT '홍길동4' FROM DUAL UNION ALL SELECT '홍길동5' FROM DUAL UNION ALL SELECT '홍길동6' FROM DUAL UNION ALL SELECT '홍길동7' FROM DUAL ) select * from ( select nm , mod(rownum -1 ,5) +1 gb2 , ceil(rownum/5) gb from t) Pivot (min(nm) For gb2 In (1 as 이름1,2 as 이름2,3 as 이름3,4 as 이름4,5 as 이름5));