---
title: "ORACLE connect by/sys_connect_by_path 生成(菜单)树全名称"
author: "jslfl"
date: "2012-07-16T15:37:10Z"
tags: ["connect", "id", "pid"]
categories: ["数据库"]
slug: "oracle-connect-by-sys-connect-by-path"
draft: false
lastmod: "2012-07-16T15:37:10Z"
id: 1595334
url: "https://jslfl.iteye.com/blog/1595334"
---

树形表结构时,经常需要看一个节点的全名称(层级的父节点名称)

id  name      pid
1   设计资料  -1 
2   目录二    1   
3   设计      1   


select t.id,t.name,t.pid,
       substr(sys_connect_by_path(t.name, '/'), 2) fullname1
 	sys_connect_by_path(t.name, '/') fullname2
  from doc_folder t
 start with t.pid = '-1'
connect by prior t.id = t.pid


id  name      pid  fullname1         fullname2
1   设计资料  -1   设计资料	     /设计资料
2   目录二    1    设计资料/目录二   /设计资料/目录二
3   设计      1    设计资料/设计     /设计资料/设计