SELECT id,
MAX(DECODE(row_number, 1, a.name)) ||
NVL(MAX(DECODE(row_number, 2, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 3, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 4, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 5, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 6, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 7, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 8, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 9, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 10, ',' || a.name)), '')||
NVL(MAX(DECODE(row_number, 11, ',' || a.name)), '') ||
NVL(MAX(DECODE(row_number, 12, ',' || a.name)), '') ag
FROM
(SELECT id, name, ROW_NUMBER() OVER(PARTITION BY name ORDER BY id) row_number FROM test) a
GROUP BY a.id
ORDER BY a.id;