表 A  字段 col    如 select  col  from  A 结果集为 春


冬我如何转成 结果集 为  4列的
春    春,夏    春,夏,秋   春,夏,秋,冬
求 高手指点下小弟在此谢过!!!

解决方案 »

  1.   


    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                                           
    ---------- ---------- ---------- ---------------                                
    春         春,夏      春,夏,秋   春,夏,秋,冬  
      

  2.   

    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);