id  父id
1   0
2   1
3   1
4   2
5   3
6   3
7   5
比如:如果id=7
要求查询id=7与
(
select id from 表A
start with id=7
connect by prior 父id=id
)
的组合,比如
那么显示出来是:
id     
7   7
7   5
7   3
7   1这个sql 应该如何写呢
http://community.csdn.net/Expert/topic/5569/5569114.xml?temp=.2292749

解决方案 »

  1.   

    这样??SQL> SELECT 7 ID,7 P_ID FROM DUAL
      2  UNION
      3  SELECT 7 ID,P_ID FROM SUB_PAR
      4  START WITH ID=7
      5  CONNECT BY PRIOR P_ID=ID;        ID       P_ID
    ---------- ----------
             7          0
             7          1
             7          3
             7          5
             7          7SQL> SELECT * FROM SUB_PAR;        ID       P_ID
    ---------- ----------
             1          0
             2          1
             3          1
             4          2
             5          3
             6          3
             7          5已选择7行。
      

  2.   

    我是想写个视图表A记录集如下:
    id  父id
    1   0(表示无父id)
    2   1
    3   1
    4   2
    5   3
    6   3
    7   5
    这个视图我希望查出的结果:
             7          1
             7          3
             7          5
             7          7
             6          6
             6          3
             6          1
             5          5
             5          3
             5          1
             4          4
             4          2
             4          1
             3          3
             3          1
             2          2
             2          1
             1          1
      

  3.   

    http://community.csdn.net/Expert/TopicView.asp?id=5569114
    http://community.csdn.net/Expert/TopicView.asp?id=5569124
    http://community.csdn.net/Expert/TopicView.asp?id=5569130大家帮个忙,三贴一并给分,谢谢了!!^_^
      

  4.   

    select id,父id   from 表A where id=7
    union all
    select id,父id   from 表A
    start with id=7
    connect by prior 父id=id
      

  5.   

    加入ORACLE的群吧;群号是:19312711