SELECT AJBH,
--PARENTVALUE,
LTRIM(SYS_CONNECT_BY_PATH(FPRY,','),') VALUUES
FROM (SELECT T.AJBH,
NVL((SELECT a.yhxm FROM SWJCDB.Jc_Jl_Swjcryb a WHERE a.yhid=T.FPRY),T.FPRY) FPRY,
(ROW_NUMBER() OVER(PARTITION BY AJBH ORDER BY SFZJRY DESC)) NUMID
FROM SWJCDB.JC_JL_RYFPB T
WHERE sshj='21')
WHERE CONNECT_BY_ISLEAF = 1
START WITH NUMID = 1
CONNECT BY NUMID - 1 = PRIOR NUMID
AND AJBH = PRIOR AJBH;