oracle,分组后,字符串以“,”合并

-----测试成功 begin
SELECT CC.cd_reserve,
       CC.CD_COMPANY,
       CC.CD_PUBLISH,
       CC.nm_data,
       CC.REMARK,
       CC.ST_RESERVE,
       SUM(CC.SN_SUM) AS SUM_ALL,
       ltrim(REPLACE(MAX(CC.sql0), ';', ','), ',') as CON_MACHINE_ALL
  FROM (select BB.*, sys_connect_by_path(BB.cd_machine_txt, ';') AS sql0
          from (select AA.*,
                       lead(AA.rn) over(PARTITION BY AA.cd_reserve order by AA.rn) rn1
                  from (SELECT C.*,
                               ci.nm_data,
                               c.sn_prefix || c.sn_num_from as PREFIX_FROM,
                               c.sn_prefix || c.sn_num_to as PREFIX_TO,
                               row_number() over(ORDER BY C.cd_reserve) rn
                          from T_RESERVED_ITEM C
                          left join common_info ci
                            on ci.cd_type = 'CD_STRESERVE'
                           and ci.cd_data = C.ST_RESERVE
                         WHERE C.DELETE_FLG = 'N'
                        
                        ) AA) BB
         START WITH rn1 IS NULL
        CONNECT BY rn1 = PRIOR rn) CC
 GROUP BY CC.cd_reserve,
          CC.CD_COMPANY,
          CC.CD_PUBLISH,
          CC.nm_data,
          CC.REMARK,
           CC.ST_RESERVE
   -----测试成功 enD    

你可能感兴趣的:(oracle)