select * from tbname t where not exists(
select 1 from tbname tt where t.id=tt.parent_id
);
select 1 from tbname tt where t.id=tt.parent_id
);
解决方案 »
- c#+oracle 汉字输入oracle后是乱码
- 用户、数据库、表空间、实例这几个基本概念之间的对应关系
- oracle中数据丢失的问题?
- [oracle text]如何过滤word、pdf文档得到文本部分?
- windows xp 下oracle数据库关了再打开就说我 协议适配器错误
- 求oracle 查询调用存储过程非常慢的解决方案,高手赐教
- 请教用@执行脚本怎样传入参数呢
- 如何能监视任意用户对某个表的UPDATE和DELETE操作,并把该用户的计算机名称或者IP地址保存到自定义表中
- 备份恢复问题!听说“牧师”满厉害,帮忙啊!
- 如何使用批处理登录oracle 并执行创建用户语句,用户名密码接收用户输入?
- ORACLE 9i 数据库的UNDOTBS表空间使用增加,不能回收.
- 在UNIX下怎样创建第二个数据库实例
select distinct parent_id id from tbname
where parent_id<>0
minus
select distinct id from tbname
) t
where t.id=tb.id(+);
bzszp(www.bzszp.533.net)
你用的Exists写的是正好是我的答案,后面一个却查找不到记录
003 它是没有子项的啊,在parent_id中没有一项是003 不就表示003 没有子项么
select distinct id from tbname
minus
select distinct parent_id id from tbname
where parent_id <>0
) t
where t.id=tb.id(+);
union
select * from tbname t where parent_id<>0
也就是说如果id 有子类,则子类显示在它的下面,没有别的要求001 电子类 0
004 电子电容 001
005 电子电阻 001
002 金属类 0
006 有色金属 002
007 无色金属 002
003 橡胶类 0
connect by prior id=parent_id;
你提供的这个语句好像多了四条记录,结果是
001 电子类 0
004 电子电容 001
005 电子电阻 001
002 金属类 0
006 有色金属 002
007 无色金属 002
003 橡胶类 0
004 电子电容 001
005 电子电阻 001
006 有色金属 002
007 无色金属 002
start with ID is not null and parent_id=0
connect by prior id=parent_id;
(
select 1 from test tt where tt.parent_id=t.id
)
union
select * from test t where parent_id<>0 and exists
(
select 1 from test tt where t.parent_id=tt.id
)
where t1.id<>t2.parent_id
select t1.* from table1 t1, table1 t2
where t1.id = t2.parent_id
where (t1.id = t2.parent_id) or t1.parent_id=0
FROM tbname AS t
WHERE t.id not in
(
select t1.id from tbname t1,tbname t2
where t1.id=t2.parent_id
);
我遇到过同你一样的问题
select * from tbname connect by prior id = parent_id start with parent-id = '0';