start with

来源:互联网 发布:写字板软件下载 编辑:程序博客网 时间:2024/04/28 16:01

--根据部门编码查询其对应的大区或大区的平级

 select *

   from t_org_department d

  where d.deptlevel = 4

  start with d.finasyscode = 'DP02035'

 connect by prior d.parentid = d.id



connect by 是结构化查询中用到的,其基本语法是:
select … from tablename
start with 条件1
connect by 条件2
where 条件3;

例:
select * from table
start with org_id = ‘HBHqfWGWPy’
connect by prior org_id = parent_id;

         简单说来是将一个树状结构存储在一张表里,比如一个表中存在两个字段:
org_id,parent_id那么通过表示每一条记录的parent是谁,就可以形成一个树状结构。

        用上述语法的查询可以取得这棵树的所有记录。
        其中:
        条件1 是根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树。
        条件2 是连接条件,其中用PRIOR表示上一条记录,比如 CONNECT BY PRIOR org_id = parent_id;就是说上一条记录的org_id 是本条记录的parent_id,即本记录的父亲是上一条记录。
        条件3 是过滤条件,用于对返回的所有记录进行过滤。

0 0
原创粉丝点击