쿼리문 질문 드립니다. 0 2 1,331

by 손님 [SQL Query] 쿼리 [2012.05.03 21:42:28]


오라클 9i 이구요,,
아래와 같이 테이블에 값이 들어 있습니다.

TABLE1
SEQ        SEQ_TITLE              SEQ_MONEY
1          사과<BR>딸기<BR>바나나   30,000
2        오렌지<BR>자몽           20,000

쿼리을 아래와 같이 나오게 하고 싶습니다.
1          사과                                                30,000
1          딸기                                                30,000
1          바나나                                             30,000
2          오렌지                                             20,000
2          자몽                                                20,000

즉,  SEQ_TITLE 컬럼 값에 <BR>로 구분된것을 ROW 로 나타내고 싶습니다.
쿼리로 가능 할까요?
답변 좀 부탁 드립니다 (__)              
by 손님 [2012.05.04 16:22:01]
with t as
( select 1 seq, '사과
딸기
바나나' seq_title, '30,000' seq_money from dual union all select 2, '오렌지
자몽', '20,000' from dual ) select seq , ltrim(substr(seq_title, p1, p2-p1), '/') seq_title , seq_money from (select seq , seq_title , seq_money , p1 , lead(p1) over(partition by seq_title order by lv) p2 from (select seq , replace('/'||seq_title||'/', '
', '/') seq_title , seq_money , level lv , instr(replace('/'||seq_title||'/', '
', '/'), '/', 1, level) p1 from t connect by level <= (length(replace('/'||seq_title||'/', '
', '/')) - length(replace(seq_title, '
'))) ) ) where p1 p2 ;

by 손님 [2012.05.04 18:44:13]
 
with t as
( select 1 seq, '사과
딸기
바나나' seq_title, '30,000' seq_money from dual union all select 2, '오렌지
자몽', '20,000' from dual ) select seq , ltrim(substr(seq_title, p1, p2-p1), '/') seq_title , seq_money from (select seq , seq_title , seq_money , p1 , lead(p1) over(partition by seq_title order by lv) p2 from (select seq , replace('/'||seq_title||'/', '
', '/') seq_title , seq_money , level lv , instr(replace('/'||seq_title||'/', '
', '/'), '/', 1, level) p1 from t connect by level <= (length(replace('/'||seq_title||'/', '
', '/')) - length(replace(seq_title, '
'))) ) ) where p1 != p2 ;
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입