表结构大概是:
Id   Dsc
1    str1
1    str2
2    str3
3    str4
3    str4
能否用一条SQL语句得出结果:
Id    Dsc        DscLen(Dsc的字段长度)
1     str1str2   8
2     str3       4
3     str4str4   8

解决方案 »

  1.   


    with t1 as
    (
         select 1 id,'str1' dsc from dual union all
         select 1 id,'str2' dsc from dual union all
         select 2 id,'str3' dsc from dual union all
         select 3 id,'str4' dsc from dual union all
         select 3 id,'str4' dsc from dual
    )select id,
           replace(wm_concat(dsc),',','') dsc,
           length(replace(wm_concat(dsc),',','')) DscLen
    from t1
    group by id
         id      dsc       DscLen
    -----------------------------------------
    1 1 str1str2 8
    2 2 str3         4
    3 3 str4str4 8