0
SELECT LPAD('*', 2*level-1)||SYS_CONNECT_BY_PATH(unit_data, '/') "battle_unit_id"
   FROM battle_units
   START WITH battle_unit_id= 600
   CONNECT BY PRIOR parent_id = battle_unit_id;

返回

/Doctrine
  /Doctrine/Air
    /Doctrine/Air/Jet powered aircraft
       /Doctrine/Air/Jet powered aircraft/F-16

我想要的只是/Doctrine/Air/Jet powered aircraft/F-16没有其他三个结果。有办法吗?

编辑:

我的甲骨文版本:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux:版本 11.2.0.3.0 - Production
NLSRTL 版本 11.2.0.3.0 - 生产

4

2 回答 2

0

如果我理解正确,您只需要树叶:

SELECT LPAD('*', 2*level-1)||SYS_CONNECT_BY_PATH(unit_data, '/') "battle_unit_id"
FROM battle_units 
WHERE connect_by_isleaf = 1  -- <<< this selects only the leaf nodes
START WITH battle_unit_id= 600
CONNECT BY PRIOR battle_unit_id = parent_id;

详见手册: http: //docs.oracle.com/cd/E11882_01/server.112/e26088/pseudocolumns001.htm#SQLRF00251

于 2014-04-15T20:54:08.943 回答
0

如果您知道该行将出现的确切级别,这是可行的。

请看这个小提琴

编辑:由于您要达到最大值,因此这可能对您有用。

于 2014-04-15T19:17:25.730 回答