WMSYS.WM_CONCAT 这个函数,我翻了一下手头上oracle 10g 的官方文档没找到。在国内搜索,搜到内容差不多,信息量最多不外乎是如下结果:http://blog.csdn.net/wh62592855/archive/2009/10/29/4745581.aspx 。
但是我在本机oracle10g r2 上运行,用over (partition by id) ,系统提示不能使用。有没有谁关于WMSYS.WM_CONCAT的详细介绍啊,英文也可以。PS:
在国外的一个帖子中,看到有说ListAgg函数更好,可以定义连接字符串内部顺序,有谁用过吗?我的oracle版本好像没这个函数

解决方案 »

  1.   

    给你个我整理的例子,希望对你有帮助:
    SQL> create table IDTABLE
    2 (
    3    id number,
    4    val varchar2(20)
    5 )
    6 ;Table createdSQL> 
    SQL> insert into IDTABLE (ID, VAL)
    2 values (10, 'abc');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (10, 'abc');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (10, 'def');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (10, 'def');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (20, 'ghi');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (20, 'jkl');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (20, 'mno');1 row inserted
    SQL> insert into IDTABLE (ID, VAL)
    2 values (20, 'mno');1 row insertedSQL> select id,val from idtable;        ID VAL
    ---------- --------------------
            10 abc
            10 abc
            10 def
            10 def
            20 ghi
            20 jkl
            20 mno
            20 mno8 rows selectedSQL> commit;Commit completeSQL> 
    SQL> SELECT ID, WMSYS.WM_CONCAT(VAL) AS ENAMES
    2    FROM IDTABLE
    3   GROUP BY ID;        ID ENAMES
    ---------- --------------------------------------------------------------------------------
            10 abc,abc,def,def
            20 ghi,jkl,mno,mnoSQL> 
    SQL> SELECT ID, WMSYS.WM_CONCAT(DISTINCT VAL) AS ENAMES
    2    FROM IDTABLE
    3   GROUP BY ID
    4   ORDER BY ID;        ID ENAMES
    ---------- --------------------------------------------------------------------------------
            10 abc,def
            20 ghi,jkl,mnoSQL> 
    SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(PARTITION BY ID) AS ENAMES
    2    FROM IDTABLE
    3   ORDER BY ID;        ID VAL               ENAMES
    ---------- -------------------- --------------------------------------------------------------------------------
            10 abc                abc,abc,def,def
            10 abc                abc,abc,def,def
            10 def                abc,abc,def,def
            10 def                abc,abc,def,def
            20 ghi                ghi,jkl,mno,mno
            20 jkl                 ghi,jkl,mno,mno
            20 mno               ghi,jkl,mno,mno
            20 mno               ghi,jkl,mno,mno8 rows selectedSQL> 
    SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(ORDER BY ID, VAL) AS ENAMES
    2    FROM IDTABLE
    3   ORDER BY ID;        ID VAL               ENAMES
    ---------- -------------------- --------------------------------------------------------------------------------
            10 abc                abc,abc
            10 abc                abc,abc
            10 def                abc,abc,def,def
            10 def                abc,abc,def,def
            20 ghi                abc,abc,def,def,ghi
            20 jkl                 abc,abc,def,def,ghi,jkl
            20 mno               abc,abc,def,def,ghi,jkl,mno,mno
            20 mno               abc,abc,def,def,ghi,jkl,mno,mno8 rows selected
      

  2.   

    http://www.itpub.net/thread-1332147-1-1.html#
      

  3.   


    行转列  
    tb
    id name
    1   a
    1   b
    2   c
    2   d
    3   eselect id,wm_concat(name) from tb group by id结果
    id name
    1  a,b
    2  c,d
    3  e
      

  4.   

    id name
    1 c
    1 b
    1 aselect id,wm_concat(name) from tb group by id结果是:
    id name
    1  c,b,a 有方法出来这个 效果吗:1 a,b,c
      

  5.   

     
    SQL> select * from www_1;
     
    ID NAME
    -- ----------
     1 c
     1 b
     1 a
     
    SQL> select id,wm_concat(name) from  (select * from www_1 order by id,name) group by id;
     
    ID WM_CONCAT(NAME)
    -- --------------------------------------------------------------------------------
     1 a,b,c
     
    SQL> 
      

  6.   

    SQL> desc IDTABLE
    Name Type   Nullable Default Comments 
    ---- ------ -------- ------- -------- 
    ID   NUMBER Y                         
    NAME NUMBER Y                         
     
    SQL> select * from IDTABLE;
     
            ID       NAME
    ---------- ----------
             1          1
             1          2
             1          3
             1         24
             1         17
             1         16
     
    6 rows selected
     
    SQL> select id,WMSYS.WM_CONCAT(name) from
      2  (select * from IDTABLE order by id,name) y group by id ;
     
            ID WMSYS.WM_CONCAT(NAME)
    ---------- --------------------------------------------------------------------------------
             1 1,2,3,17,24,16
     
    SQL> 
      

  7.   

    试试这样.
    select id,max(name) from (select id,wm_concat(name)over(partition by id order by name asc) name from www_1) group by id;
      

  8.   

    SQL> select id,wm_concat(name) from  (select * from www_1 order by id,name) group by id ;
     
    ID WM_CONCAT(NAME)
    -- --------------------------------------------------------------------------------
     1 a,b,c,r,t,e
     
    SQL> select id,max(name) from (select id,wm_concat(name)over(partition by id order by name asc) name from www_1) group by id  ;
     
    ID MAX(NAME)
    -- --------------------------------------------------------------------------------
     1 a,b,c,e,r,t