现有表t_belong
id father_id child_id1 1002 1003
2 1002 1004
3 1003 1005
4 1004 1006
5 1004 1007如果通过 father_id=1002 获取该记录下所有的child_id记录即:1003,1004,1005,1006,1007;
类似一个树形结构;如果根据根节点获取下面所有的子节点
id father_id child_id1 1002 1003
2 1002 1004
3 1003 1005
4 1004 1006
5 1004 1007如果通过 father_id=1002 获取该记录下所有的child_id记录即:1003,1004,1005,1006,1007;
类似一个树形结构;如果根据根节点获取下面所有的子节点
id number(18,0),
father_id number(18,0),
child_id number(18,0)
);insert into t_belong(id,father_id,child_id) values(1, 1002, 1003);
insert into t_belong(id,father_id,child_id) values(2, 1002, 1004);
insert into t_belong(id,father_id,child_id) values(3, 1003, 1005);
insert into t_belong(id,father_id,child_id) values(4, 1004, 1006);
insert into t_belong(id,father_id,child_id) values(5, 1004, 1007);
start with t.father_id=1002
connect by prior t.child_id=t.father_id
start with t.father_id=1002
connect by prior t.child_id=t.father_id
create table t_belong(
id number(18,0),
father_id number(18,0),
child_id number(18,0)
);insert into t_belong(id,father_id,child_id) values(1, 1002, 1003);
insert into t_belong(id,father_id,child_id) values(2, 1002, 1004);
insert into t_belong(id,father_id,child_id) values(3, 1003, 1005);
insert into t_belong(id,father_id,child_id) values(4, 1004, 1006);
insert into t_belong(id,father_id,child_id) values(5, 1004, 1007);SELECT lpad('|-', (level - 1) * 4, ' ') || lpad('『', 2) || id ||
rpad('』', 2) id
FROM t_belong
CONNECT BY PRIOR child_id = father_id
START WITH id = 2;
..