listagg

wm_concat和listagg都可以把列拼接成行,11g下wm_concat没有自带的排序功能,弱爆了,要么在内层排序增加开销,要么用over(partition by b order by a) 产生一堆废数据,listagg方便多了,用法:
a    |    b
-----------
A    |    1
B    |    2
C    |    3
select listagg(a,',') within group (order by b) ,listagg(b,',') within group (order by b)
from xxx --其中','可替换成其他字符
---------------------
A,B,C   |   1,2,3





sql.append("select distinct(a.fwzl),lx.id,a.fwcode, a.fwid, c.qlid, c.qlrmc,c.syqzsh,a.fwdh,a.jzmj");
        sql.append(" from " + SCHEMA.FWDJ + ".Tpf_Jcdjb a, (select listagg(r.qlrmc ,',') within group (order by r.qlrmc)  as qlrmc,");
        sql.append(" listagg( b.syqzsh ,',') within group (order by r.qlrmc) as syqzsh,b.fwcode,b.qlid from " + SCHEMA.FWDJ + ".tpf_syqdjb b, " + SCHEMA.FWDJ + ".tpf_qlr r");
        sql.append(" where r.ywslid = b.ywslid and r.id = b.qlrid  and r.sfls = 0  and b.sfls = 0 and b.fwcode is not null ");

        sql.append(" group by b.fwcode, b.qlid) c," + SCHEMA.LSJZBH + ".tpkr_lsjzfwcqgx lx  where c.fwcode = a.fwcode and  a.fwcode =lx.fwcode and lx.fwcode=c.fwcode and a.sfls=0");
       

你可能感兴趣的:(list)