[英]Recursive CTE gives "Error at line 1/16: ORA-00905: missing keyword" error on Oracle SQL
WITH RECURSIVE cte (n) AS
(
SELECT 1
UNION ALL
SELECT n + 1 FROM cte WHERE n < 5
)
SELECT * FROM cte;
I copied the above code from Oracle documentation.我从 Oracle 文档中复制了上述代码。 It works fine when I run it in MySQL, but I get the error message "Error at line 1/16: ORA-00905: missing keyword" when I run it in Oracle's Apex workshop.
当我在 MySQL 中运行它时,它运行良好,但是当我在 Oracle 的 Apex 研讨会中运行它时,我收到错误消息“第 1/16 行错误:ORA-00905:缺少关键字”。 It is strange that a sample from Oracle documentation does not work.
奇怪的是 Oracle 文档中的示例不起作用。 Any idea what the problem is?
知道问题是什么吗?
It is syntactically invalid to have RECURSIVE
in the query.在查询中使用
RECURSIVE
在语法上是无效的。 Whichever documentation you used it was not for an Oracle database;无论您使用哪个文档,它都不是 Oracle 数据库; you want this documentation .
你想要这个文档。
Additionally, SELECT 1
is not valid as you have a SELECT
without a FROM
clause;此外,
SELECT 1
无效,因为您的SELECT
没有FROM
子句; it should be SELECT 1 FROM DUAL
.它应该是
SELECT 1 FROM DUAL
。
The fixed code should be:固定代码应该是:
WITH cte (n) AS
(
SELECT 1 FROM DUAL
UNION ALL
SELECT n + 1 FROM cte WHERE n < 5
)
SELECT * FROM cte;
Which outputs:哪个输出:
N ![]() |
---|
1 ![]() |
2 ![]() |
3 ![]() |
4 ![]() |
5 ![]() |
In oralce, you can't use SELECT 1, that is only allowed in Mysql在 oralce 中,您不能使用 SELECT 1,这仅在 Mysql 中允许
As is aid ORACLE rdms is not Mysql RDMS正如援助 ORACLE rdms 不是 Mysql RDMS
select * from V$VERSION;
BANNER![]() |
BANNER_FULL ![]() |
BANNER_LEGACY ![]() |
CON_ID ![]() |
---|---|---|---|
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production ![]() |
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production ![]() Version 21.3.0.0.0 ![]() |
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production ![]() |
0 ![]() |
WITH cte (n) AS
(
SELECT 1 FROm DUAL
UNION ALL
SELECT n + 1 FROM cte WHERE n < 5
)
SELECT * FROM cte;
N ![]() |
---|
1 ![]() |
2 ![]() |
3 ![]() |
4 ![]() |
5 ![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.