在SQL的树型结构中,很多时候,知道某一节点的值,需要查找该节点的所有子节点(包括多级)的功能,这时就需要用到如下的用户自定义函数. 表结构如下: ID int Dep_Type int Dep_Code varchar(50) Dep_Name varchar(50) Dep_Dian int Dep_FathID int Dep_Opera varchar(50) Dep_Status int Dep_AddTime datetime 用户自定义函数如下: create function f…
with t as ( select b.* from Base_Department b where ParentId = 'cce4152c-3483-4334-b68d-155da627bca0' union all select a.* from Base_Department a join t b on a.ParentId=b.DepartmentId ) select * from t…
import java.io.File; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; /** * 遍历xml所有节点(包括子节点下还有子节点多层嵌套) */ public class TestXML { public static void main(final Strin…
T-Sql 递归查询(给定节点查所有父节点.所有子节点的方法)   -- 查找所有父节点with tab as( select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316--子节点 union all select b.Type_Id,b.ParentId,b.Type_Name  from  tab a,--子节点数据集  Sys_ParamType_V2_0 b  --父节点数据集 where a.…
背景                                                                                                       项目中遇到一个需求,要求查处菜单节点的所有节点,在网上查了一下,大多数的方法用到了存储过程,由于线上环境不能随便添加存储过程, 因此在这里采用类似递归的方法对菜单的所有子节点进行查询. 准备                                                  …
如下一张表test:id name pid----------- ---------- -----------1 电器 NULL2 家电 13 冰箱 24 洗衣机 25 电脑 16 笔记本 57 平板 58 组装机 79 品牌机 7--查询电脑的所有子节点. 可采用标准sql的with实现递归查询: with subRecord(id,name,pid) as ( select id,name,pid from test where id = 5 union all select test.id…
---SQL SERVER 2000 遍历父子关系數據表(二叉树)获得所有子节点 所有父节点及节点层数函数---Geovin Du 涂聚文--建立測試環境Create Table GeovinDu([ID] Int, fatherID Int, [Name] Varchar(10))Insert A Select 1, 0, '中国'Union All Select 2, 1, '广东'Union All Select 3, 1, '北京'Union All Select 4, 2, '深圳特区…
/** * dom4j递归解析所有子节点 * * @param childElements * @param mapEle * @return */ public Map<String, Object> getElementsToString(String print) { //解析返回的xml字符串,生成document对象 Document document = null; Map<String,Object> mapEle = null; try{ document = Do…
-- 查找所有父节点with tab as( select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316--子节点 union all select b.Type_Id,b.ParentId,b.Type_Name  from  tab a,--子节点数据集  Sys_ParamType_V2_0 b  --父节点数据集 where a.ParentId=b.Type_Id  --子节点数据集.paren…
if object_id('[tb]') is not null drop table [tb] go create table [tb]([modeid] int,modename varchar(20),parentid int) insert [tb] select 100 ,'商品管理', 0 union all select 101 ,'定单管理', 0 union all select 102 ,'用户管理', 0 union all select 104 ,'学院广告', 0 un…