高分请教:该SQL语句如何写? see sql reference about "Hierarchical Queries" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 connect by start with select decode(parentid,1,'1','1') parentid,id,datafrom tab connect by prior id=parentidstart with parentid is null例子:SQL> select * from aa;ID FID-- ---1 02 13 14 25 36 46 57 rows selectedSQL> SQL> select lpad(id,level*2+length(id),' ') id 2 from aa 3 connect by prior id = fid 4 start with fid = 0;ID-------------------------------------------------------------------------------- 1 2 4 6 3 5 67 rows selectedSQL> select decode(fid,'1','1','1') fid,id 2 from aa 3 connect by prior id=fid 4 start with fid='1';FID ID--- --1 21 41 61 31 51 6 请教高手一个关于PL/SQL连接Oracle数据库的问题!!! java eclipse内说表或视图不存在 问题,求达人帮帮 to_char的返回类型 求一个SQL语句 oracle有什么好的入门书 高手进来!!!一个关于主从表联合查询的问题!!! 请教:在存储过程中使用动态Sql语句的方法,up有分 oledbdatareader的问题,急啊 如何使用临时表 oracle连接不上对方的数据库 请教一游标实例,在先守候! 如果字段A='D' 那么返回B,如果字段A='C',那么返回E,在SELECT 语句中怎么写,一时忘记了,
start with
from tab
connect by prior id=parentid
start with parentid is null例子:
SQL> select * from aa;ID FID
-- ---
1 0
2 1
3 1
4 2
5 3
6 4
6 57 rows selectedSQL>
SQL> select lpad(id,level*2+length(id),' ') id
2 from aa
3 connect by prior id = fid
4 start with fid = 0;ID
--------------------------------------------------------------------------------
1
2
4
6
3
5
67 rows selectedSQL> select decode(fid,'1','1','1') fid,id
2 from aa
3 connect by prior id=fid
4 start with fid='1';FID ID
--- --
1 2
1 4
1 6
1 3
1 5
1 6