您的位置:首页 > 数据库 > Oracle

Oracle递归查询 Start with…Connect By用法

2011-10-27 10:44 866 查看
http://www.wnshare.com/archives/454.html

oracle中的select语句可以用START WITH…CONNECT BY PRIOR子句实现递归查询,其基本语法如下:

select … from <TableName>
where <Conditional-1>
start with <Conditional-2>
connect by <Conditional-3>


<Conditional-1>:过滤条件,用于对返回的所有记录进行过滤。

<Conditional-2>:查询结果重起始根结点的限定条件,种子号,整形字符串都可以,只要有增长规则。

<Conditional-3>:连接条件,父子id关系

从Root往树末梢递归

select * from TBL_TEST
start with id=1
connect by prior id = parentId


从末梢往树ROOT递归

select * from TBL_TEST
start with id=5
connect by prior pid = id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: