数据库语句-递归树
oracle
1.用递归的方法 public List recursion(String departId,List list){ StringBuffer sb=new StringBuffer(); sb.append("from Department dept where dept.departParent='"+departId+"'"); List deptList=dao.find(sb.toString()); if(deptList.size()>0){ list.add(deptList); for(int i=0;i<deptList.size();i++){ deptList.get(i).setDept_list(recursion(deptList.get(i).getDepartId(),list)); } } return list; } 2.直接用sql语句去查询 select * from oms_dept start with dept_id='1409' connect by prior dept_id = dept_parent
DB2
with emp_temp(id,name)as ( select id,name from emp where name ='xxx' union all select e.id ,e.name from emp e ,emp_temp t where t.id = e.id )select name from emp_temp