现在表结构是这样的
条目1----条目2
条目2----条目3
条目2----条目4
条目3----空
条目4----条目5
条目5----空
现在已知条目1,想根据条目1查找出所有相关的条目。遍历的终止是为空的条目。
其中,有的条目对应多个条目,而且条目的深度不确定。
想问问这个循环该怎么写?最好别是递归,不好理解
条目1----条目2
条目2----条目3
条目2----条目4
条目3----空
条目4----条目5
条目5----空
现在已知条目1,想根据条目1查找出所有相关的条目。遍历的终止是为空的条目。
其中,有的条目对应多个条目,而且条目的深度不确定。
想问问这个循环该怎么写?最好别是递归,不好理解
http://topic.csdn.net/u/20111124/17/76e30f79-26f2-43fb-a16f-c27f08db79d2.html
/**
* @param PostCode
* 根据父节点获取所有子节点岗位编号
* @return 树的子结点集合
*/
@SuppressWarnings("unchecked")
public List<JobType> getPostCodeChilds(String postCode) {
List<JobType> ret = new ArrayList<JobType>();
List<JobType> retRecursive = null;
List<JobType> children = getChildrenNodes(postCode); for(JobType job0 : children){
String displayOrder = job0.getDisplyOrder();
if(!CommUtil.isNull(displayOrder) && displayOrder.equals("po")){
ret.add(job0);
}else{
retRecursive = getPostCodeChilds(job0.getJobTypeCode());
if(ret.size() == 0){
ret = retRecursive;
}else{
ret.addAll(retRecursive);
}
}
}
return ret;
}
for(int i=0;i<=fatherItem.getChildrenSize();i++){
if(item[i] == null) {
//got it
} else {
hasNullAmongChildren(item[i]);
}
}
}这是深搜先序遍历
select d.* from basis_organization d
start with d.organizationid='O00001'
connect by prior d.organizationid=d.parentid;
根据你的表结构,修改表明和字段名
select t.* from table t
start with t.id= :p
connect by ..
select ... from tablename start with 条件1
connect by 条件2
where 条件3;例:select * from table
start with org_id = 'HBHqfWGWPy'
connect by prior org_id = parent_id; 简单说来是将一个树状结构存储在一张表里,比如一个表中存在两个字段:
org_id,parent_id那么通过表示每一条记录的parent是谁,就可以形成一个树状结构。
用上述语法的查询可以取得这棵树的所有记录。
其中:条件1 是根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树。
条件2 是连接条件,其中用PRIOR表示上一条记录,比如 CONNECT BY PRIOR org_id = parent_id就是说上一条记录的org_id 是本条记录的parent_id,即本记录的父亲是上一条记录。
条件3 是过滤条件,用于对返回的所有记录进行过滤。