表 tree
字段 master
sub
sales
insert into tree values
(
insert into tree values
(
insert into tree values
(
insert into tree values
(
insert into tree values
(
insert into tree values
(
SQL> select * from tree;
MASTER SUB SALES
主
主
主
主
主
主
如果用樹型結構表示如下:
SQL> select * from tree
start with sub=
connect by prior master=sub;
MASTER SUB SALES
主
SQL> select * from tree
start with master=
connect by prior master=sub;
MASTER SUB SALES
主
主
主
主
好
SQL> select sys_connect_by_path(MASTER
start with master=
connect by prior master=sub;
SYS_CONNECT_BY_PATH(MASTER
/主
/主
/主
/主
SQL> select sys_connect_by_path(MASTER
start with sub=
connect by prior master=sub;
SYS_CONNECT_BY_PATH(MASTER
/主
/主
/主
/主
SQL> select sys_connect_by_path(MASTER
start with sub is not null
connect by prior master=sub;
SYS_CONNECT_BY_PATH(MASTER
/主
/主
/主
/主
/主
/主
/主
/主
/主
/主
select sys_connect_by_path(MASTER
start with sub is not null
connect by prior sub = master;
SYS_CONNECT_BY_PATH(MASTER
/主
/主
/主
/主
/主
/主
/主
/主
/主
/主
From:http://tw.wingwit.com/Article/program/Oracle/201311/16554.html