|
|
http://zhidao.baidu.com/question/58346136.html?fr=qrl
行列转换很复杂,给你做参考
转换前:
select * from test;
A B C
-- -- --
1 2 3
2 2 4
4 3 3
3 1 6
4 3 6
6 5 9
8 8 8
转换后:
A B C D E
------------ -------------- --------------- ------------- -------------
1 2 4 3 4
2 2 3 1 3
3 4 3 6 6
牛逼的方法(悟其精髓确有难度)
select regexp_substr(str, '[^,]+', 1, 1) a,
regexp_substr(str, '[^,]+', 1, 2) b,
regexp_substr(str, '[^,]+', 1, 3) c,
regexp_substr(str, '[^,]+', 1, 4) d,
regexp_substr(str, '[^,]+', 1, 5) e
from (select regexp_substr(str, '[^(\.)]+', 1, rownum) str
from (select max(a) || '.' || max(b) || '.' || max(c) str
from (select substr(sys_connect_by_path(a, ','), 2) a,
substr(sys_connect_by_path(b, ','), 2) b,
substr(sys_connect_by_path(c, ','), 2) c
from (select rownum child,
a,
b,
c,
lead(rownum, 1) over(order by rownum) parent
from test) t
start with child = 1
connect by prior parent = child))
connect by rownum < length(regexp_replace(str, '[^(\.)]', '')) + 2); |
|