Convert rows into columns [message #607959] |
Thu, 13 February 2014 22:43 |
Xandot
Messages: 235 Registered: January 2014 Location: India
|
Senior Member |
|
|
hi friends ,
Please help me out ....
my Query:--
with t as
(select 'abc,efg,ijk' a from dual
union all
select '12,45,78' from dual)
select * from t;
o/p:--
col1 ----- col2
-------------------------------
abc ----- 12
efg ----- 45
ijk ----- 78
Thanks.....
[Updated on: Thu, 13 February 2014 22:54] Report message to a moderator
|
|
|
|
|
|
Re: Convert rows into columns [message #607987 is a reply to message #607983] |
Fri, 14 February 2014 01:14 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> with
2 t as (
3 select 'abc,efg,ijk' a from dual
4 union all
5 select '12,45,78' from dual
6 ),
7 data as ( select ','||a||',' val, rownum coln from t ),
8 split as (
9 select substr(regexp_substr(val, ',[^,]*', 1, column_value),2) item,
10 column_value rown, coln
11 from data,
12 table(cast(multiset(select level from dual
13 connect by level <
14 length(val)-length(replace(val,',','')))
15 as sys.odciNumberList))
16 )
17 select max(decode(coln,1,item)) col1,
18 max(decode(coln,2,item)) col2
19 from split
20 group by rown
21 order by rown
22 /
COL1 COL2
------------ ------------
abc 12
efg 45
ijk 78
3 rows selected.
|
|
|
|
Re: Convert rows into columns [message #607992 is a reply to message #607989] |
Fri, 14 February 2014 01:33 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Sure there are other ways but with the same kind of methods as there are several ways to split and several ways to pivot.
I'm sure others will post some of them.
|
|
|