TERADATA存储过程返回数据错误

时间:2018-06-10 06:37:04

标签: stored-procedures teradata

我创建了一个执行这些步骤的过程:

  1. 删除历史悠久的桌子的最后8天
  2. 然后我们将过去8天的更新数据添加回历史表
  3. 返回历史记录表的所有数据
  4. 当我添加最后一步(数字3)时,我收到下面屏幕截图中显示的错误。你能帮我理解我应该做些什么来使这项工作吗?

    enter image description here

    REPLACE PROCEDURE SP_New_Procedure ()
    DYNAMIC RESULT SETS 1 
    SQL SECURITY OWNER
    
    BEGIN 
    ------------Deleting last 8 days of data -------------------------------
    
       DELETE FROM History_Table
            WHERE Date BETWEEN CURRENT_DATE -INTERVAL '8' DAY(FORMAT 'YYYYMMdd') 
                            AND CURRENT_DATE -INTERVAL '1' DAY(FORMAT 'YYYYMMdd');
    
    ------------Inserting updated last 8 days of data------------------------
    
       INSERT INTO History_Table
       SELECT
          FinalTable.*
       FROM
          Data_Query AS FinalTable;
    
    
     ------------Return All values from updated History_Table-------------------
    
         SELECT * FROM History_Table;
    
    END;
    

    谢谢!

    丹尼尔

1 个答案:

答案 0 :(得分:0)

Teradata遵循标准SQL,您必须使用游标语法(它不是应该避免处理数据的实际游标)来返回结果集。没有游标,您只能返回单行INTO变量。

REPLACE PROCEDURE SP_New_Procedure ()
DYNAMIC RESULT SETS 1 
SQL SECURITY OWNER

BEGIN 
------------Deleting last 8 days of data -------------------------------

   DELETE FROM History_Table
        WHERE Date BETWEEN CURRENT_DATE - 1 
                       AND CURRENT_DATE - 8

------------Inserting updated last 8 days of data------------------------

   INSERT INTO History_Table
   SELECT
      FinalTable.*
   FROM
      Data_Query AS FinalTable;


 ------------Return All values from updated History_Table-------------------

   BEGIN
      DECLARE cur CURSOR WITH RETURN ONLY FOR
      SELECT * FROM History_Table;

      OPEN cur; -- don't close it, otherwise there's no result
   END;

END;

希望History_Table被该日期列分区。