注意:两个函数不同版本返回不同
1、11g wm_concat,listagg返回为clob
2、listagg排序问题,使用时每个字段可以单独根据某个字段排序,也可以使用同一 个字段排序,这样就排序后的字段顺序就是一致的了。
—下面是工作中使用时的sql,同一个身份证两条补贴,合并两条补贴为一条,再关联
create or replace view viw_zhcx_qx_list as
select c.“PERSON_ID”,c.“BTGG01010”,c.“BTGG01007”,c.“DEPARTMENT”,c.“TYPE”,c.“TYPE_NAME”,c.“SUBSIDY_START_TIME”,c.“NEXT_REVIEW_DATE”,c.“SUBSIDY_TYPE”,c.“BTGG01016”,c.“BTGG01017”,c.“SUBSIDY_ACTUAL_TIME”,
to_char(b.btgg01011, ‘yyyy-MM-dd’) birthday, --出生年月
b.btgg01008, --性别代码DIC=SEX,取值:01=女,02=男
b.btgg01027, --联系方式
getParentIdForRegion(b.street) reg_area, --户籍区
b.street reg_street, --户籍街道的区划ID代码 :DIC=REGION
b.juwei reg_juwei,
getParentIdForRegion(b.live_street) live_area, --居住区
b.live_street, --居住街道的区划ID代码:DIC=REGION
n.ID sub_area --发放区
from (select a.person_id,
a.btgg01010,
a.btgg01007,
a.department,
–11g wm_concat返回为clob
to_char(listagg(a.TYPE,’,’) within GROUP (ORDER BY a.TYPE)) type,
to_char(listagg(decode(a.TYPE,‘01’,‘生活补贴’,‘02’,‘护理补贴’),’,’) within GROUP (ORDER BY a.TYPE)) type_Name,
to_char(listagg(to_char(a.SUBSIDY_START_TIME, ‘yyyy-MM’),’,’) within GROUP (ORDER BY a.TYPE)) SUBSIDY_START_TIME,
to_char(listagg(to_char(a.NEXT_REVIEW_DATE, ‘yyyy-MM’),’,’) within GROUP (ORDER BY a.TYPE)) NEXT_REVIEW_DATE,
to_char(max(a.SUBSIDY_TYPE)) SUBSIDY_TYPE,
to_char(max(a.BTGG01016)) BTGG01016,
to_char(max(a.BTGG01017)) BTGG01017,
to_char(listagg(to_char(a.SUBSIDY_ACTUAL_TIME, ‘yyyy-MM’),’,’) within GROUP (ORDER BY a.TYPE)) SUBSIDY_ACTUAL_TIME
–to_char(listagg(a.bank) within GROUP (ORDER BY a.TYPE)) bank
from dfcb_person_senionty a
where a.subsidy_state=‘01’
group by a.person_id, a.btgg01010, a.btgg01007, a.department) c,
dfcb_person_base_info b,
v_dc_region t,
v_dc_region n
where --c.person_id = b.id(+);
c.btgg01010 = b.btgg01010
and c.department = t.ID
and t.PARENT_CODE = n.CODE
;