select AD_DEPARTMENT_CODE, AD_DEPARTMENT_UP_LEVEL, AD_DEPARTMENT_NAME from (select AD_DEPARTMENT_CODE, AD_DEPARTMENT_UP_LEVEL, AD_DEPARTMENT_NAME from AD_DEPT_ARCHITECTURE order by AD_DEPARTMENT_UP_LEVEL, AD_DEPARTMENT_CODE) start with AD_DEPARTMENT_CODE = '0' connect by prior AD_DEPARTMENT_CODE = AD_DEPARTMENT_UP_LEVEL;
|
|
SELECT APR_CODE, APR_CODE_UP, NAMES FROM (SELECT A.MEDIA_CODE || '|' || A.CHANNEL_CODE || '|' || A.COLUMN_CODE AS APR_CODE, A.MEDIA_CODE_UP || '|' || A.CHANNEL_CODE_UP || '|' || A.COLUMN_CODE_UP AS APR_CODE_UP, DECODE((B.MEDIA_NAME || '-' || C.CHANNEL_CODE || '-' || D.COLUMN_NAME), '--', '产品关系', (B.MEDIA_NAME || '|' || C.CHANNEL_CODE || '|' || D.COLUMN_NAME)) NAMES FROM COLUMNS D, CHANNEL C, MEDIA B, AD_PRODUCT_RELATION A WHERE A.MEDIA_CODE = B.MEDIA_CODE(+) AND A.MEDIA_CODE = C.MEDIA_CODE(+) AND A.CHANNEL_CODE = C.CHANNEL_CODE(+) AND A.MEDIA_CODE = D.MEDIA_CODE(+) AND A.CHANNEL_CODE = D.CHANNEL_CODE(+) AND A.COLUMN_CODE = D.COLUMN_CODE(+)) START WITH APR_CODE = '0|0|0' CONNECT BY PRIOR APR_CODE = APR_CODE_UP
这里利用'-' 和'|'来进行区分,找出了树状结构的根 为了构建树, (1)先建立了树结构的根,字段这里都设为“0”或者“ |
oracle中进行简单树查询(递归查询) ,PRIOR、CONNECT_BY_ROOT的使用
最新推荐文章于 2023-08-10 20:13:43 发布
本文介绍了在Oracle数据库中如何进行树形结构的递归查询,重点讲解了PRIOR和CONNECT_BY_ROOT这两个关键字的使用方法,帮助读者理解如何在数据库中处理层次关系数据。
摘要由CSDN通过智能技术生成