日期:2014-05-16  浏览次数:20422 次

oracle 将某字段值进行拼接
今天用到 记录一下。
SELECT COL1, LTRIM(MAX(SYS_CONNECT_BY_PATH(COL2, ',')), ',') COL2
  FROM (SELECT COL1,
               COL2,
               MIN(COL2) OVER(PARTITION BY COL1) COL2_MIN,
               (ROW_NUMBER() OVER(ORDER BY COL1, COL2)) +
               (DENSE_RANK() OVER(ORDER BY COL1)) NUMID
          FROM (SELECT 1 COL1, DISPLAYNAME COL2 FROM TBL_AAAA_ORGANIZATION))
START WITH COL2 = COL2_MIN
CONNECT BY NUMID - 1 = PRIOR NUMID
GROUP BY COL1;