본문 바로가기

database

다중 Row 결과를 단일행으로 컴마로 분리해 출력하는 방법

SELECT     SUBSTR (MAX (SYS_CONNECT_BY_PATH (ename, ',')), 2) path#

FROM       (SELECT ename, ROWNUM rnum

            FROM   emp)

START WITH rnum = 1

CONNECT BY PRIOR rnum = rnum - 1

 

 

 

SELECT     deptno, SUBSTR (MAX (SYS_CONNECT_BY_PATH (ename, ',')), 2) path#

FROM       (SELECT ename, deptno, ROW_NUMBER () OVER (PARTITION BY deptno ORDER BY ename) rnum

            FROM   emp)

START WITH rnum = 1

CONNECT BY PRIOR rnum = rnum - 1

AND        PRIOR deptno = deptno

GROUP BY   deptno


'database' 카테고리의 다른 글

JEUS XAException발생시 처리방법  (0) 2007.11.20
ORACLE 캐릭터셋 변경  (0) 2007.02.27
Never Use a RETURN Statement Inside a Loop  (0) 2006.12.26
EXECUTE IMMEDIATE  (0) 2006.12.16
오라클 테이블정보 쿼리  (0) 2006.12.06