oracle的 listagg() WITHIN GROUP () 行转列函数的使用

参考如下:

复制代码
select listagg(reveitemname, ',') within group (order by reveitemname)fdb from 
(
    select 
    distinct
    gg.projid,
    gg.contractname||
    case 
        when gg.revetype='1'   and   gg.rrighttype='2'    then '房产' 
        when gg.revetype='1'   and   gg.rrighttype='3'    then '土地' 
        when gg.revetype='1'   and   gg.rrighttype='4'    then '设备' 
        when gg.revetype='1'   and   gg.rrighttype='10'   then '汽车' 
        when gg.revetype='1'   and   gg.rrighttype='5'    then '其他物证' 
        when gg.revetype='2'   and   gg.rrighttype='6'    then '股权' 
        when gg.revetype='2'   and   gg.rrighttype='8'    then '其他物权' 
        when gg.revetype='2'   and   gg.rrighttype='18'   then '专利权' 
        when gg.revetype='10'  and   gg.rrighttype='19'   then '浮动抵押' 
        when gg.revetype='11'  and   gg.rrighttype='7'    then '应收账款' 
    end  reveitemname  
    from
    (
        select 
        pci.*,
        (select count(1) from comm_attachment_relation c where c.objectid=pci.contractid  and c.attachmenttype in ('23','29') ) as ishavepactfile ,        
        (
            select max(rrighttype) from CRM_COUNTERGUARANTEE_PRO tt ,guarantyandcontractapprrel ww
            where tt.projid=ww.projid
            and tt.faserialid=ww.faserialid
            and ww.contractid=pci.contractid
        ) as rrighttype,        
        (
            select max(tt.revetype) from CRM_COUNTERGUARANTEE_PRO tt ,guarantyandcontractapprrel ww
            where tt.projid=ww.projid
            and tt.faserialid=ww.faserialid
            and ww.contractid=pci.contractid
        ) as revetype
        from PROJ_CONTRACT_INFO  pci  order by substr(pci.contractcode, 11,15),pci.createtime
    ) gg  
)where  projid=xxx
复制代码

 查询结果显示:

夫妻连带保证-反担保,个人保证-反担保,企业保证-反担保,委托保证合同,质押-反担保股权

end;

posted @   xh_Blog  阅读(151)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2018-08-02 Long类型的坑,第一次遇见
点击右上角即可分享
微信分享提示