简体   繁体   English

Connect By 子句适用于 11g,但不适用于 Oracle 8i:“ORA-01436:用户数据中的 CONNECT BY 循环”

[英]Connect By clause works on 11g but not on Oracle 8i : "ORA-01436: CONNECT BY loop in user data"

I found the code for a row generator from this question Create View with 365 days我从这个问题中找到了行生成器的代码Create View with 365 days

CREATE VIEW year_days (the_day) AS
SELECT TRUNC(SYSDATE, 'YYYY') + (LEVEL-1) AS the_day
FROM DUAL
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'),11)), 'DDD'))
/
SELECT * FROM year_days

Since I don't have CREATE privileges, I modified it to an inline-query form :由于我没有CREATE权限,我将其修改为内联查询表单:

SELECT
    year_days.* 
FROM
    (
    SELECT TRUNC(SYSDATE, 'YYYY') + (LEVEL-1) AS the_day
    FROM DUAL
    CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'),11)), 'DDD'))
    ) year_days

The inline-query code above works perfectly fine on one of our Oracle 11g R2 (v11.2.0.3.0) instance, as well as on Oracle's own LiveSQL (19c, v19.2.0.0.0).上面的内联查询代码在我们的 Oracle 11g R2 (v11.2.0.3.0) 实例之一以及 Oracle 自己的 LiveSQL (19c, v19.2.0.0.0) 上运行得非常好。

However, it does not work on the instance that it needs to run on, which is 8i (v8.1.7.4.0).但是,它不适用于它需要运行的实例,即 8i (v8.1.7.4.0)。 I get ORA-01436: CONNECT BY loop in user data .我得到ORA-01436: CONNECT BY loop in user data

At first glance it seems that 8i sees an infinite loop in that code, but not 11g and up.乍一看,8i 似乎在该代码中看到了无限循环,但在 11g 及更高版本中没有。 Why ?为什么 ?

Note: I know 8i is old.注意:我知道 8i 是旧的。 I have no control over that.我对此无能为力。

If it doesn't have to be a connect by query, how about something simpler, such as如果它不必是查询连接,那么更简单的东西怎么样,例如

select rownum
from all_objects
where rownum <= to_number(to_char(last_day(add_months(trunc(sysdate, 'YYYY'),11)), 'DDD'));

or perhaps也许

select rownum 
from (select null from dual
      group by cube (1, 2, 3, 4, 5, 6, 7, 8, 9, 20)
     )
where rownum <= to_number(to_char(last_day(add_months(trunc(sysdate, 'YYYY'),11)), 'DDD'));

which both should work on Oracle 8i.两者都应该在 Oracle 8i 上工作。

More nice row generator techniques on OraFAQ Forum, here: http://www.orafaq.com/forum/t/95011/102589/ OraFAQ 论坛上更多不错的行生成器技术,请访问: http : //www.orafaq.com/forum/t/95011/102589/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM