1

我有分层数据。

select lpad(' ', 4*(level-1))||NAME 
from from_sql 
where where_sql 
CONNECT BY PRIOR id = parent_id 
START WITH parent_id is null 
  • 工作,好吧。

出去:

la1
    la2
    la3
        la4
    la5
        la6
        la7
la8
    la9

我需要:

1    la1
1.1        la2
1.2        la3
1.2.1            la4
1.3        la5
1.3.1            la6
1.3.2            la7
2    la8
2.1        la9

如何用点数计算?

4

1 回答 1

3

试试这个:

SELECT SYS_CONNECT_BY_PATH(r, '.'), name
FROM
  (SELECT rank() over (partition BY parent_id
                    ORDER BY id) r,
                id,
                name,
                parent_id
  FROM from_sql 
 WHERE where_sql) t
   CONNECT BY
   PRIOR id = parent_id START WITH parent_id IS NULL

是一个小提琴

于 2012-06-15T12:07:05.707 回答