游标选择中使用的表从编译时重构为运行时

时间:2018-06-28 12:21:25

标签: sql stored-procedures runtime-error teradata

我得到CALL Failed. [7691] SP_name:Table used in cursor select is restructured from compile-time to run-time.

我相信这是因为我在存储过程中循环遍历了日期:

If min_mnth <= max_mnth THEN
        LoopMnth:
        FOR cc_mnth AS cc_cdates CURSOR FOR
            SELECT To_Char(calendar.calendar_date, 'yyyy-mm') as mnth
            from sys_calendar.calendar
            where To_Char(calendar.calendar_date, 'yyyy-mm') between min_mnth and max_mnth
            and mnth not in (select report_mnth from tb1)
            and mnth >= '2017-08'
            group by 1 order by 1
.....

一个有趣的事实是,这样的过程有时会起作用,大部分时候我的循环迭代次数就会减少。

我仅找到此相关信息https://community.teradata.com/t5/Database/Error-7691-P1-Table-used-in-cursor-select-is-restructured-from/td-p/36691

他们建议SET SESSION DATEFORM = INTEGERDATE-同样的错误。

此错误是什么以及如何解决?

1 个答案:

答案 0 :(得分:0)

然后您将得到这样的错误

1) SET SESSION DATEFORM = INTEGERDATE
2) Recreate your procedure