select to_char(wmsys.wm_concat(DISTINCT name)) from T

解决方案 »

  1.   

     with t as
      (select 10 xh, 'aa' name
         from dual
       union all
       select 20 xh, 'bb' name
         from dual
       union all
       select 20 xh, 'cc' name
         from dual
       union all
       select 30 xh, 'cc' name
         from dual
       union all
       select 40 xh, 'cc' name
         from dual
       union all
       select 50 xh, 'cc' name
         from dual
       union all
       select 60 xh, 'dd' name
         from dual
       union all
       select 70 xh, 'ee' name
         from dual
       union all
       select 80 xh, 'ee' name
         from dual)
     select max(str)
       from (select to_char(wm_concat(name) over(order by name)) str
               from (select distinct name from t));
      

  2.   

    里面有重复的记录,也需要的,比如
    xh   name
    10 aa
    20 bb
    30 bb
    40 aa
    50 cc
    60 cc
    需要结果是 aa,bb,aa,cc,怎么改呢?
      

  3.   

    去掉distinct就是了
    select to_char(wmsys.wm_concat(name)) from T
      

  4.   


    以上语句,distinct去掉即可
      

  5.   

    是不是连续重复的两个,在结果中只出现一次?
    select max(str)
    from (
      select to_char(wm_concat(name) over(order by xh)) str
      from (select xh,name,lag(name,1,' ')over(order by xh) pre from t )
      where pre<>name
    )
      

  6.   


    不对的,去掉DISTINCT出来是这个,不是我要的结果是aa,bb,aa,cc,dd
      

  7.   

    with t as
      (select 10 xh, 'aa' name
         from dual
       union all
       select 20 xh, 'bb' name
         from dual
       union all
       select 20 xh, 'bb' name
         from dual
       union all
       select 30 xh, 'aa' name
         from dual
       union all
       select 40 xh, 'cc' name
         from dual
       union all
       select 50 xh, 'cc' name
         from dual
       union all
       select 60 xh, 'dd' name
         from dual
       union all
       select 70 xh, 'ee' name
         from dual
       union all
       select 80 xh, 'ee' name
         from dual)
    select max(str)
    from (
      select to_char(wm_concat(name) over(order by xh)) str
      from (select xh,name,lag(name,1,' ')over(order by xh) pre from t )
      where pre<>name
    )结果
    MAX(STR)
    ---------------------aa,bb,aa,cc,dd,ee