日期:2014-05-17 浏览次数:20753 次
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 ---------- ---------- ---------- --------------- 春 春,夏 春,夏,秋 春,夏,秋,冬
------解决方案--------------------
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);