关于orcale的层级查询

关于orcale的层级查询的,新建一个字段,用来代表父子关系,例如 0001 代表父节点,那00010001和00010002代表子节点,以此类推,这种怎么通过已有的父子关系生成

例如
id parent_id catId
1 -1 0001
2 1 00010001
3 1 00010002
4 3 000100020001
5 3 000100020002
catid怎么生成?
注:根节点0001为初始化的数据

UPDATE 表名 T SET T.CATID = (WITH TMP AS (SELECT ID, REPLACE(SYS_CONNECT_BY_PATH(TO_CHAR(RK, 'fm0000'), ','), ',') CAT FROM (SELECT ID, PARENT_ID, ROW_NUMBER() OVER(PARTITION BY PARENT_ID ORDER BY ID) RK FROM 表名) START WITH PARENT_ID = -1 CONNECT BY PRIOR ID = PARENT_ID) SELECT CAT FROM TMP X WHERE X.ID = T.ID);

你可能感兴趣的:(oracle)