根据部门模糊搜索 ,后台会自动拼树 


select t.*,level from b_Jt_Departments t start with  dept_name like '%科%' and parent_id='302' connect by prior t.dept_id=t.parent_id 

 --通过根节点遍历子节点 
select t.*,level from family t start with parentid=1 connect by prior id=parentid;  
 
--通过子节点向根节点追溯 
select t.*,level from family t start with id=5 connect by prior parentid=id;         
 
--查找直接子节点(下一层) 
select t.*,level from family t where level = 2 start with parentid=1 connect by prior id=parentid;   
 
 --查找直接父节点(上一层) 
select t.*,level from family t where level = 2 start with id=5 connect by prior parentid=id;        
 
--通过根节点遍历子节点 
select level,t.* from ORG_DEPARTMENT_INFO t start with parent_id=-1 connect by prior dept_id=parent_id;   
--查找直接子节点(下一层) 
select level,t.* from ORG_DEPARTMENT_INFO t where level = 2 start with parent_id=-1 connect by prior dept_id=parent_id;   
 --通过子节点向根节点追溯 
select level,t.* from ORG_DEPARTMENT_INFO t start with dept_id=10000260 connect by prior parent_id=dept_id;        
--查找直接父节点(上一层) 
select level,t.* from ORG_DEPARTMENT_INFO t where level = 2 start with dept_id=10000260 connect by prior parent_id=dept_id;      
 --查找直接父节点(上一层)    
select t.* from ORG_DEPARTMENT_INFO t where level = 2 start with dept_id=10000260 connect by prior parent_id=dept_id;        
 
--通过根节点向子节点追溯 
 
select level, t.*from SM_ORGANIZATION t start with t.org_id='114e0e3c-dbd1-4c2e-9d10-d5fd1e243961' connect by prior org_id=parent_id;  
 --通过子节点向根节点追溯 
select level, t.*  from SM_ORGANIZATION t start with org_id='9e67e1f4-f4b0-4669-b4e1-1dca132bb4d7' connect by prior parent_id=org_id;       



发布评论
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

Oracle 设置 密码可以重复使用 the password cannot be reused知识解答
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。