0

请帮助我在 Oracle 中执行以下操作。

我有类似列的东西id,我需要串联

Id
1
2
3
4
5
6
8
9
9

我需要一个返回的查询1,2,3,4,5,6,7,8,9,9

我怎样才能做到这一点?

4

2 回答 2

1

尝试这个,

WITH t(ID) AS
(
SELECT 1 FROM dual
UNION
SELECT 2 FROM dual
UNION 
SELECT 3 FROM dual
UNION
SELECT 4 FROM dual
)
SELECT LISTAGG(ID, ',') WITHIN GROUP (ORDER BY ID)
FROM t;
于 2013-10-05T03:25:27.713 回答
0

尝试

select ltrim(max(sys_connect_by_path(id, ',')), ',')
  from (select id, rownum t
          from yourtable t)
connect by prior t = t - 1
 start with t = 1;
于 2013-10-05T02:19:28.127 回答