zoukankan      html  css  js  c++  java
  • 转:Oracle中Level函数的使用实例.

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

    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

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    上篇用到的matcher函数
    lambdaj学习
    Redis高级应用——2
    Redis入门
    从gitee 下载代码到本地
    CSS中对图片(background)的一些设置心得总结
    nodejs 安装Ionic 和cordova
    Spring MVC内容协商机制详解
    基于Servlet3.0的编程式SpringMVC实例详解
    基于Junit的Spring集成测试方法
  • 原文地址:https://www.cnblogs.com/tracy/p/1712635.html
Copyright © 2011-2022 走看看