有一个sql的树形结构
uid name pid
1 a 0
2 b 1
3 c 2
4 d 3
5 e 0
6 f 5
如何给定一个Uid,,查询所有的父亲节点,
比如.给定uid=4
查询出.0,1,2,3
现在跟距
select uid
from t
start with uid=4
connect by prior pid=uid;
的方法 可以查出
4 3
3 2
2 1
1 0那请问如何可以加一条
0 -
uid name pid
1 a 0
2 b 1
3 c 2
4 d 3
5 e 0
6 f 5
如何给定一个Uid,,查询所有的父亲节点,
比如.给定uid=4
查询出.0,1,2,3
现在跟距
select uid
from t
start with uid=4
connect by prior pid=uid;
的方法 可以查出
4 3
3 2
2 1
1 0那请问如何可以加一条
0 -
解决方案 »
- oracle9i 查询优化
- 请教oralce中查询数据横向显示
- Bind Variables(绑定变量)和Substitution Variables(替代变量)到底有什么 区别啊
- 请问为什么sql loader导入CSV文件后产生日志文件不能追加?
- 建表问题
- ORACLE 中的二进制类型用什么表示?
- 请问如何计算oracle表容量?
- 如果我刚刚delete了一张表,想把数据找回来,有没有办法呢?
- 哪位大哥帮忙写一个15位身份证号码转化为18位的Oracle函数?
- 我用PLSQL DEVELOPER登陆oracle的时候总提示出错
- Oracle初学者问题
- 树形结构.通过子节点获取所有父节点(还有一个临时表的问题)
from t_test
start with id = 4
connect by prior pid = id
union all
select pid, null
from t_test
where connect_by_isleaf = 1
start with id = 4
connect by prior pid = id
from t_test
start with id=4
connect by prior pid=id)
select id,pid from t
union all
select pid,null from t where leaf=1
create table t as
select 1 u_id,'a' nm,0 pid from dual union all
select 2,'b',1 from dual union all
select 3,'c',2 from dual union all
select 4,'d',3 from dual union all
select 5,'e',0 from dual union all
select 6,'f',5 from dual
/
select u_id,pid
from t
start with u_id=4
connect by prior pid=u_id
union all
select pid,null
from t
where connect_by_isleaf=1
start with u_id=4
connect by prior pid=u_id;
U_ID PID
---------- ----------
4 3
3 2
2 1
1 0
0
--