단일 행으로 된 아래의 칼럼을 특정문자(|)를 기준으로 행으로 나타내려면 어떻게 해야 할까요? 0 1 1,095

by 김병훈 [SQL Query] [2015.06.27 09:33:12]


단일 행으로 된 아래의 칼럼을 | 를 기준으로 행으로 나타내려면 어떻게 해야 할까요?
regexp_substr 구문을 쓰면 될것 같은데... 도움 부탁합니다.

0000039685|1|2,0000055566|4|5

=>

0000039685 0000055566
1 4
2 5

 

by swlee710 [2015.06.27 17:07:13]
with t as (
select '0000039685|1|2,0000055566|4|5' txt
from dual)
select decode(lv,1,col1,2,col2,3,col3) aa, decode(lv,1,col4,2,col5,3,col6) bb
from (
    select regexp_substr(txt1,'[^|]+',1,1) col1,regexp_substr(txt1,'[^|]+',1,2) col2,regexp_substr(txt1,'[^|]+',1,3)col3
          ,regexp_substr(txt2,'[^|]+',1,1) col4,regexp_substr(txt2,'[^|]+',1,2) col5,regexp_substr(txt2,'[^|]+',1,3)col6
          , lv
    from (
            select regexp_substr(txt,'[^,]+',1,1) txt1, regexp_substr(txt,'[^,]+',1,2) txt2
            from t),(select level lv from dual connect by level <= 3));

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입