connect by问题

noteasytoregister 2011-10-27 04:54:30
select sys_connect_by_path(column_name, ',') -- select *
from user_tab_columns
where table_name='EMP'
connect by prior column_id+1=column_id
start with column_id=1


这段SQL一直在Executing...,几分钟都未完成,象是出现了死循环,请问哪里错了?
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
noteasytoregister 2011-10-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 opps_zhou 的回复:]

SQL code

select sys_connect_by_path(column_name, ',')
from user_tab_columns
where connect_by_isleaf = 1
connect by prior column_id = column_id - 1 and prior table_name = table_name
start with t……
[/Quote]
我的写法中table_name='EMP'应该最后才判断的,所以慢了。
我发现下面的写法更快些:

select sys_connect_by_path(column_name, ',') -- select *
from (select * from user_tab_columns
where table_name='EMP')
connect by prior column_id+1=column_id
start with column_id=1
opps_zhou 2011-10-27
  • 打赏
  • 举报
回复

select sys_connect_by_path(column_name, ',')
from user_tab_columns
where connect_by_isleaf = 1
connect by prior column_id = column_id - 1 and prior table_name = table_name
start with table_name='EMP' and column_id = 1;


17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧