Oracle 中的递归
我在预言中有下表:
Parent(arg1, arg2)
并且我想要关系父级的传递闭包。也就是说,我想要下表,
Ancestor(arg1, arg2)
这在Oracle中怎么可能?
我正在执行以下操作:
WITH Ancestor(arg1, arg2) AS (
SELECT p.arg1, p.arg2 from parent p
UNION
SELECT p.arg1 , a.arg2 from parent p, Ancestor a
WHERE p.arg2 = a.arg1
)
SELECT DISTINCT * FROM Ancestor;
我收到错误
*Cause: column aliasing in WITH clause is not supported yet
*Action: specify aliasing in defintion subquery and retry
Error at Line: 1 Column: 20
如何在没有列别名的情况下解决此问题?
I have the following table in an oracle:
Parent(arg1, arg2)
and I want the transitive closure of the relation parent. That is, I want the following table
Ancestor(arg1, arg2)
How is this possible in Oracle?
I am doing the following:
WITH Ancestor(arg1, arg2) AS (
SELECT p.arg1, p.arg2 from parent p
UNION
SELECT p.arg1 , a.arg2 from parent p, Ancestor a
WHERE p.arg2 = a.arg1
)
SELECT DISTINCT * FROM Ancestor;
I get the error
*Cause: column aliasing in WITH clause is not supported yet
*Action: specify aliasing in defintion subquery and retry
Error at Line: 1 Column: 20
How can I solve this without column aliasing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Oracle
仅从11g
第 2 版开始支持递归CTE
。在早期版本中,使用
CONNECT BY
子句:Oracle
only supports recursiveCTE
since11g
Release 2.In earlier versions, use
CONNECT BY
clause:Oracle 允许递归查询。
请参阅:http://www.adp-gmbh.ch/ora/sql/connect_by .html
当然,这些通常假设分层数据都在一张表中。将其拆分为单独的表会使事情变得复杂。
Oracle allows recursive queries.
See: http://www.adp-gmbh.ch/ora/sql/connect_by.html
Of course, these usually assume the hierarchical data is all in one table. Splitting it into separate tables makes things complicated.