Oracle高级查询之CONNECT BY
select a.*, level from dlsys.tcUnit a where nvl(validFlag,1) = 1 start with SeniorUnitId is null connect by SeniorUnitID = prior UnitID order siblings by DisplayOrder Oracle中的select语句可以用start with ... connect by prior ...子句实现递归查询,connect by 是结构化查询中用到的,其基本语法是: select ... from where <过滤条件,用于对返回的所有记录进行过滤> start with <根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树> connect by [prior] <连接条件,其中用prior表示上一条记录,比如:connect by prior t.id = t.parent_id就是说上一条记录的id 是本条记录的parent_id,即本记录的父亲是上一条记录> 下面我们直接来看实例,查询'KING'的所有下属雇员。SQL语句如下: [sql] view plain copy select * from scott.emp e start with e.ename = 'KING' connect by