zoukankan      html  css  js  c++  java
  • oracle 中start with 的用法

    在重新开发已经有过的一个项目时,参考原本的sql,在一个存储过程中有用到 start with connect by,从网络找到下面资料。

    Oracle 提供了start with connect by 语法结构可以实现递归查询。
     from test;
     DAY_NUMBER MSISDN
    -------------------- ---------- --------------------
    200803                        1 13800
    200803                        3 13800
    200803                        2 13800
    200803                        2 13801
    200803                        4 13804
    200803                        5 13804
    200803                        7 13804
    200803                        8 13804
    200803                        6 13802
    200803                        6 13801
    200803                        7 13801
    200803                        8 13801

    SQL>
    SQL> select * from test
      2       start with day_number=1
      3       connect by  prior day_number=day_number-1 and prior msisdn= msisdn
      4      ;
     DAY_NUMBER MSISDN
    -------------------- ---------- --------------------
    200803                        1 13800
    200803                        2 13800
    200803                        3 13800


     connect by 语法结构
     如上面说看到的 例子, 其语法结构为  start with condition  connect by  condition (含 prior 关键字)
    start with conditon 给出的seed 数据的范围, connect by  后面给出了递归查询的条件,prior 关键字表示父数据,prior 条件表示子数据需要满足父数据的什么条件。

    start with day_number=1
         connect by  prior day_number=day_number-1 and prior msisdn= msisdn

  • 相关阅读:
    JavaScript使用方法和技巧大全
    PHP JSON 数据解析代码
    效率较高的php下读取文本文件的代码
    PHP操作MongoDB 数据库
    安装mongo php拓展
    MongoDB与MySQL的插入、查询性能测试
    java字符数组char[]和字符串String之间的转换
    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
    python操作txt文件中数据教程[2]-python提取txt文件
    python操作txt文件中数据教程[1]-使用python读写txt文件
  • 原文地址:https://www.cnblogs.com/liuss2014/p/6045711.html
Copyright © 2011-2022 走看看