0

我如何找到一个文件夹下的所有孩子?就像在资源管理器中你有一个文件夹,你有文件夹+文件夹等。

我想找到文件夹 2 下的所有文件夹

我正在使用 ORACLE 数据库。

Folder 1
| |
| Folder 2
| |  |
| |  Folder 3
| |  |  |
| |  |  Folder 7
| |  |  |
| |  |  Folder 8
| |  |
| |  Folder 4
| |
| Folder 5
| |
| Folder 6 
|
Folder 10

这个查询给了我父层次结构。

SELECT AL_ITEM_ID, AL_FATHER_ID, AL_DESCRIPTION
FROM ALL_LISTS
CONNECT BY AL_ITEM_ID = PRIOR AL_FATHER_ID
start with AL_DESCRIPTION = 'Folder 7'
4

1 回答 1

2

我认为这会起作用:

Select
    al_item_id, 
    al_father_id,
    al_description
From 
    all_lists
Connect By 
    Prior al_item_id = al_father_id
Start With
    al_description = 'Folder 2'
Where
    Level > 1

如果没有,这几乎肯定会,这取决于在连接之前还是之后评估 where :

Select
    al_item_id,
    al_father_id,
    al_description
From (
    Select
        al_item_id, 
        al_father_id,
        al_description,
        level as lvl
    From 
        all_lists
    Connect By 
        Prior al_item_id = al_father_id
    Start With
        al_description = 'Folder 2'
    ) x
Where
    lvl > 1
于 2013-09-09T19:36:25.113 回答