select distinct(t.child_device_id) from t_d_dev_belong_relationship t start   with   t.father_device_id in (11553,11545,11541,11537) connect   by   prior   t.child_device_id=t.father_device_id
备注:t_d_dev_belong_relationship这是某层次关系表,里面包含了系统中所有的层次关系,我知道这个sql是查询某个父设备(电力设备)下面的所有子设备,类似于写了一个递归的方法——就是查到了某个父设备的子设备后,再查子设备的子设备,知道查出所有的子设备为止。
但是我不理解connect   by   prior   t.child_device_id=t.father_device_id这一部分的含义,麻烦解释一下,这样我下次写不用死记硬背

解决方案 »

  1.   

    这个是查询父子设备的条件,
    指明连接查询条件是 前一条记录的子设备ID=当前记录的父设备ID
      

  2.   

    http://wenku.baidu.com/view/f58113768e9951e79b8927f7.html
      

  3.   

    prior是表示递归的意思吗?如果把prior去掉,表示什么意思呢?我plsql测试了一下,显示一直在executing死掉了
      

  4.   

    connect by prior t.child_device_id=t.father_device_id我的理解是将前一条记录的孩子设备ID作为本次查询的父设备ID
      

  5.   

    connect by prior t.child_device_id=t.father_device_id中t.father_device_id的父节点是t.child_device_id,也就是t.child_device_id
      t.father_device_id
      t.father_device_id
      t.father_device_id
      

  6.   

    SQL是不是少什么·正常树结构不是还有
    start with 吗?
    哈哈~