读书人

关于 结果集 列转行的有关问题

发布时间: 2012-09-23 10:28:11 作者: rapoo

关于 结果集 列转行的问题
表 A 字段 col

如 select col from A

结果集为






我如何转成 结果集 为 4列的
春 春,夏 春,夏,秋 春,夏,秋,冬


求 高手指点下

小弟在此谢过!!!

[解决办法]

SQL code
SQL> create table a(col varchar2(3));SQL> insert into a select '春' from dual;SQL> insert into a select '夏' from dual;SQL> insert into a select '秋' from dual;SQL> insert into a select '冬' from dual;SQL> select regexp_substr(wm_concat(col),'[^,]+') col1,  2      regexp_substr(wm_concat(col),'[^,]+[,]+[^,]+') col2,  3      regexp_substr(wm_concat(col),'[^,]+[,]+[^,]+[,]+[^,]+') col3,  4      wm_concat(col) col4 from a;COL1       COL2       COL3       COL4                                           ---------- ---------- ---------- ---------------                                春         春,夏      春,夏,秋   春,夏,秋,冬
[解决办法]
SQL code
select max(decode(rn, 1, col)) col1,       max(decode(rn, 2, col)) col2,       max(decode(rn, 3, col)) col3,       max(decode(rn, 4, col)) col4 from (select wm_concat(col) over (order by rownum) col, rownum rn from a); 

读书人网 >oracle

热点推荐