无效的上下文是cursor_name%rowtype

时间:2017-04-02 17:02:57

标签: database plsql db2 procedure database-administration

..在使用它的上下文中无效.SQLCODE = -206,SQLSTATE = 42703 你可以让我知道这个问题并澄清为什么吗? 环境:DB2(启用oracle兼容性) 代码类似于:`

CREATE OR REPLACE PACKAGE body PACK1 IS
    PROCEDURE PROC1 AS 
        CURSOR CUR1 IS SELECT COL1,COL2 FROM TABLE1 WHERE NOT EXISTS ( SELECT * FROM TABLE2 ) AND COL3 = 'Y';
        TYPE TYP1 IS TABLE OF CUR1%ROWTYPE INDEX BY BINARY_INTEGER; --facing issue here.. please clarify
        ALIAS1 TYP1;
    BEGIN
            ...STATEMENT1..
            OPEN CUR1;
            LOOP 
            FETCH CUR1 BULK COLLECT INTO ALIAS1 LIMIT 1000;
            ...STATEMENTS2...
            EXIT WHEN CUR1%NOTFOUND;
            END LOOP;

            ....STATEMENTS3...
    END PROC1;
END PACK1;`

line4([在遇到错误的行中提供注释)。请帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

在程序声明之前移动 TYPE 的声明:

CREATE OR REPLACE PACKAGE BODY PACK1
IS
   TYPE TYP1 IS TABLE OF CUR1%ROWTYPE
      INDEX BY BINARY_INTEGER;

   PROCEDURE PROC1
   AS
      CURSOR CUR1
      IS
         SELECT COL1, COL2
           FROM TABLE1
          WHERE NOT EXISTS (SELECT * FROM TABLE2) AND COL3 = 'Y';

      ALIAS1   TYP1;
   BEGIN
      ...STATEMENT1..
      OPEN CUR1;

      LOOP
         FETCH CUR1 BULK COLLECT INTO ALIAS1 LIMIT 1000;

         ...STATEMENTS2...
         EXIT WHEN CUR1%NOTFOUND;
      END LOOP;
   ....STATEMENTS3...
   END PROC1;
END PACK1;

我很久以前就遇到过这个问题,希望这有帮助