对于这样一份数据:
我们想得到下面这样一份查询结果:
可以使用如下的查询语句:
select connect_by_root(child_col) root, level ,
decode(connect_by_isleaf,0,'No',1,'Yes') is_leaf, sys_connect_by_path(child_col,'/') path
decode(connect_by_isleaf,0,'No',1,'Yes') is_leaf, sys_connect_by_path(child_col,'/') path
from tree www.2cto.com
start with parent_col is null connect by prior child_col=parent_col;
树形查询的重点在于 start with ... connect by prior .... 语句
以及 connect_by_root ,connect_by_isleaf,sys_connect_by_path这三个函数,
decode是一般常用的函数。
decode是一般常用的函数。