博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分析函数学习1 level
阅读量:2502 次
发布时间:2019-05-11

本文共 1461 字,大约阅读时间需要 4 分钟。

level is a pseudo column used with CONNECT BY and denotes the node level of the tree structure.

[@more@]For example, given the following department/sub-department layering architecture, we have an Accounting department within a Financials department within a Software department, that is,

Software

OS
Financials
Spreadsheets
Accounting
The existence of a valid "parent" department can be enforced with a foreign key constraint on a department name column. This constraint ensures that IF a department has a parent, it is an existing department in the same table.

CREATE TABLE dept

(dept_name VARCHAR2(20) PRIMARY KEY,
parent_name VARCHAR2(20),
CONSTRAINT fk_dept2_parent_name
FOREIGN KEY (parent_name) REFERENCES dept);
The result of SELECT * FROM DEPT is:

DEP_NAME PARENT_NAME

-------- ------------
Software NULL
OS Software
Financials Software
Spreadsheet Financials
Accounting Financials
The following SQL statement uses LEVEL to denote the level number of the node in the tree structure.

SELECT

LEVEL, parent_name, dept_name
FROM
dept
CONNECT BY
prior dept_name = parent_name
START WITH
dept_name = 'Software'
ORDER BY LEVEL;
The result is:

LEVEL PARENT_NAME DEPT_NAME

---------- -------------------- --------------------
1 Software
2 Software OS
2 Software Financials
3 Financials Spreadsheets
3 Financials Accounting

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/219138/viewspace-913418/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/219138/viewspace-913418/

你可能感兴趣的文章
beta阶段第六次scrum meeting
查看>>
SpringBoot+MybatisPlus实现批量添加的两种方式
查看>>
vue 设计结构
查看>>
Sqlerver2005+按照ID分组取前几条
查看>>
Python的编码和解码
查看>>
docker
查看>>
停车场系统安全岛设计施工要求
查看>>
Docker实战
查看>>
asp.net core结合Gitlab-CI实现自动化部署
查看>>
RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.7 版本发布
查看>>
EasyNVR H5无插件摄像机直播解决方案前端解析之:关于直播页面和视频列表页面切换的问题...
查看>>
django搭建一个小型的服务器运维网站-拿来即用的bootstrap模板
查看>>
redis事务
查看>>
Java_基础语法之dowhile语句
查看>>
HDU 2175 汉诺塔IX
查看>>
PAT 甲级 1021 Deepest Root
查看>>
查找代码错误.java
查看>>
vc获取特殊路径(SpecialFolder)
查看>>
单例模式
查看>>
int(3)和int(11)区别
查看>>