请教关于oracle connect by 和 start with 的用法

求大侠说一下。
connect by prior ,在实际的开发应用中什么时候会用到?

萧十郎
浏览 146回答 2
2回答

凤凰求蛊

给你看个例子你就明白了SQL> SELECT * FROM DEP;DEPID DEPNAME UPPERDEPID----------- -------------------------------------------------------------------------------- -----------0 General Deparment1 Development 02 QA 03 Server Development 14 Client Development 15 TA 26 Porject QA 2--SQL> SELECT RPAD( ' ', 2*(LEVEL-1), '-' ) || DEPNAME "DEPNAME",CONNECT_BY_ROOT DEPNAME "ROOT",CONNECT_BY_ISLEAF "ISLEAF",LEVEL ,SYS_CONNECT_BY_PATH(DEPNAME, '/') "PATH"FROM DEPSTART WITH UPPERDEPID IS NULLCONNECT BY PRIOR DEPID = UPPERDEPID;DEPNAME ROOT ISLEAF LEVEL PATH------------------------------ ------------------- ---------- ---------- --------------------------------------------------------------------------------General Deparment General Deparment 0 1 /General Deparment-Development General Deparment 0 2 /General Deparment/Development---Server Development General Deparment 1 3 /General Deparment/Development/Server Development---Client Development General Deparment 1 3 /General Deparment/Development/Client Development-QA General Deparment 0 2 /General Deparment/QA---TA General Deparment 1 3 /General Deparment/QA/TA---Porject QA General Deparment 1 3 /General Deparment/QA/Porject QA1. CONNECT_BY_ROOT 返回当前节点的最顶端节点2. CONNECT_BY_ISLEAF 判断是否为叶子节点,如果这个节点下面有子节点,则不为叶子节点3. LEVEL 伪列表示节点深度4. SYS_CONNECT_BY_PATH函数显示详细路径,并用“/”分隔

拉莫斯之舞

递归查询,当数据结构呈现为树形、链表形时非常有效。例如,菜单、组织机构等。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL
Oracle