• oracle树结构查询


    详细参考:http://blog.csdn.net/crazyxingjc/article/details/7756299

    语法:

    select * from table 
      start with cond1
      connect by cond2
      where cond3;

    典型的查询方式:

    (1)查子节点

    select t.id, t.pid, t.name from t_tree t
      start with t.id = 100 --开始节点
      connect by prior t.id = t.pid; -- id优先,向下查子节点
      -- 或 connect by t.pid = prior t.id

    (2)查父节点

    select t.id, t.pid, t.name from t_tree t
      start with t.id = 100 --开始节点
      connect by prior t.pid = t.id; -- pid优先,向上查父节点
      -- 或 connect by t.id = prior t.pid

    (3)只查本节点,不加prior即可

  • 相关阅读:
    hdu1159 LCS模板题
    RabbitMQ入门
    Dubbo
    SpringMVC
    MySQL的再理解
    ElasticSearch
    redis入门学习
    Swagger
    SSM整合
    MybatisPlus
  • 原文地址:https://www.cnblogs.com/sleepyy/p/3096877.html
Copyright © 2020-2023  润新知