当前位置: 代码迷 >> Oracle管理 >> 需SQL语句
  详细解决方案

需SQL语句

热度:42   发布时间:2016-04-24 05:25:01.0
需求一个SQL语句
现有表t_belong
id father_id child_id

1 1002 1003
2 1002 1004
3 1003 1005
4 1004 1006
5 1004 1007

如果通过 father_id=1002 获取该记录下所有的child_id记录即:1003,1004,1005,1006,1007;
类似一个树形结构;如果根据根节点获取下面所有的子节点





------解决方案--------------------
SQL code
select wm_concat( child_ID ) from t_belong t     start with t.father_id=1002     connect by prior t.child_id=t.father_id
------解决方案--------------------
SQL code
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);
  相关解决方案