티스토리 뷰
* 한 컬럼 중복제거 후 이어 붙이기
SELECT LAW_ID,
SUBSTR(XMLAGG(SYS.XMLTYPE.CREATEXML('<'||FLAG||'>,' || CONTRACT_GESTALT||'</'||FLAG||'>') ORDER BY CONTRACT_GESTALT).EXTRACT('/a1/text()'), 2) CONTRACT_GESTALT,
SUBSTR(XMLAGG(SYS.XMLTYPE.CREATEXML('<'||FLAG||'>,' || MEMO1||'</'||FLAG||'>') ORDER BY MEMO1).EXTRACT('/a1/text()'), 2) MEMO1
FROM (
SELECT
LAW_ID,
CONTRACT_GESTALT,NVL2(CONTRACT_GESTALT, 'a' || ROW_NUMBER() OVER (PARTITION BY LAW_ID, CONTRACT_GESTALT ORDER BY CONTRACT_GESTALT),
'a2') AS FLAG,
MEMO1,NVL2(MEMO1, 'a' || ROW_NUMBER() OVER (PARTITION BY LAW_ID, MEMO1 ORDER BY MEMO1),
'a3') AS FLAG1
FROM LAW_OP_FUND)
GROUP BY LAW_ID
* 중복제거 없이 이어 붙이기
SELECT
LAW_ID,
SUBSTR (MAX (SYS_CONNECT_BY_PATH (CONTRACT_GESTALT, ',')), 2) CONTRACT_GESTALT
FROM (SELECT LAW_ID, CONTRACT_GESTALT,
ROW_NUMBER () OVER (PARTITION BY LAW_ID ORDER BY CONTRACT_GESTALT) rnum
FROM LAW_OP_FUND)
START WITH rnum = 1
CONNECT BY PRIOR rnum = rnum - 1 AND PRIOR LAW_ID = LAW_ID
GROUP BY LAW_ID
또는
SELECT
LAW_ID,
MAX(LTRIM(SYS_CONNECT_BY_PATH(CONTRACT_GESTALT,','),',')) AS CONTRACT_GESTALT
FROM
(
SELECT LAW_ID,CONTRACT_GESTALT,ROW_NUMBER() OVER(PARTITION BY LAW_ID ORDER BY ROWNUM) AS RN
FROM LAW_OP_FUND T1
--where LAW_ID ='2014091700002'
)
START WITH RN = 1
CONNECT BY PRIOR LAW_ID = LAW_ID AND PRIOR RN = RN - 1
GROUP BY LAW_ID
ORDER BY LAW_ID ASC
'Database' 카테고리의 다른 글
[MYSQL]mysql-bin 삭제 (0) | 2014.10.01 |
---|---|
[ORACLE]각각 다른 컬럼업데이트시 다른 테이블 업데이트 TRIGGER (0) | 2014.09.26 |
[ORACLE]날짜 함수 및 날짜구하기 (0) | 2014.09.18 |
[ORACLE] 없는 데이터 강제로 만들기 (0) | 2014.09.16 |
[ORACLE] 오라클 재구동 (0) | 2014.08.13 |
- Total
- Today
- Yesterday
- mssql
- 설정
- select
- Windows
- IP
- apache
- 데이터
- DATABASE
- Shell
- Oracle
- delete
- 리눅스
- 테이블
- Linux
- 자동차
- 파일
- 백업
- java
- Toad
- 윈도우
- table
- sql
- server
- tomcat
- 오라클
- 서버
- eclipse
- DB
- MySQL
- user
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |