表的内容: COLA     COLB
4401 沥青混凝土
4401 水泥混凝土
4405 水泥混凝土
4406 沥青混凝土
4406 碎石混凝土
4412 沥青混凝土
查询后要求结果:
4401 沥青混凝土,水泥混凝土
4405 水泥混凝土
4406 沥青混凝土,碎石混凝土
4412 沥青混凝土
测试数据..
create table tb(COLA number, COLB varchar2(10));
insert into tb values(4401,'沥青混凝土');
insert into tb values(4401,'水泥混凝土');
insert into tb values(4405,'水泥混凝土');
insert into tb values(4406,'沥青混凝土');
insert into tb values(4406,'碎石混凝土');
insert into tb values(4412,'沥青混凝土');

解决方案 »

  1.   

    FYI.http://community.csdn.net/Expert/topic/5037/5037398.xml?temp=.4377863http://community.csdn.net/Expert/topic/5244/5244199.xml?temp=.3989679
      

  2.   

    http://blog.csdn.net/dinya2003/archive/2004/11/30/198816.aspx
      

  3.   

    10g版本可用 wm.concat()函数实现select COLA,wm.concat(COLB) from 表 group by COLA ;
     
      

  4.   

    简单的行转列
    SQL> select cola, ltrim(max(sys_connect_by_path(colb, ',')), ',') from
      2  (select row_number() over(partition by cola order by cola,rowid) rn,tb.* from tb)
      3  start with rn = 1
      4  connect by prior rn = rn - 1 and prior cola = cola
      5  group by cola;
     
          COLA LTRIM(MAX(SYS_CONNECT_BY_PATH(
    ---------- --------------------------------------------------------------------------------
          4401 沥青混凝土 ,水泥混凝土
          4405 水泥混凝土
          4406 沥青混凝土 ,碎石混凝土
          4412 沥青混凝土
     
      

  5.   

    9i以及之前用sys_connect_by_path,start with ,connect by ....再通过分析函数去实现