PLS-00386:类型不匹配发现FETCH光标之间和到变量(PLS-00386: type mis

2019-07-22 00:37发布

以下包抛出:PLS-00386:类型不匹配发现在FETCH光标之间和INTO变量“V_STUDYTBL”

代码的目的:定义两种类型的包外,一个用于将一串数字发送到存储过程,另一种是用于返回从MY_TABLE对应的行

预先感谢您的输入。

Create OR REPLACE Type InputTyp  AS VARRAY(200) OF VARCHAR2 (1000);

CREATE  TYPE OBJTYP AS OBJECT
   (
    A            NUMBER,
    B             VARCHAR2 (1000),       
    C        VARCHAR2 (100)       
 );
CREATE TYPE OutputTyp IS VARRAY (2000) OF   OBJTYP;
/

CREATE OR REPLACE PACKAGE my_package
AS
   PROCEDURE my_procedure(p_StudyNum   IN     InputTyp,
                                     p_StdyDtl        OutputTyp);
END my_package;
/
CREATE OR REPLACE PACKAGE BODY my_package
AS
   PROCEDURE MyProcedure(p_StudyNum   IN     InputTyp,
        p_StdyDtl        OutputTyp)
IS
  i            BINARY_INTEGER := 1;
  j            BINARY_INTEGER := 1;
  CURSOR c_StudyTbl
  IS
     SELECT A,  B, C
       FROM my_table
      WHERE Study_Number = p_StudyNum(i);

  v_StudyTbl   OBJTYP;
BEGIN
  p_StdyDtl := OutputTyp ();
  LOOP
     --  This is the first cursor opened for each of the items in the list.
      EXIT WHEN i > p_StudyNum.count;

     OPEN c_StudyTbl;
     LOOP

        FETCH c_StudyTbl INTO v_StudyTbl;
        EXIT WHEN c_StudyTbl%NOTFOUND;

        p_StdyDtl.EXTEND ();
        p_StdyDtl (j).A := v_StudyTbl.A;
        p_StdyDtl (j).B := v_StudyTbl.B;
        p_StdyDtl (j).C := v_StudyTbl.C;
        j := j + 1;
     END LOOP;
     CLOSE c_StudyTbl;
    i := i + 1;
  END LOOP;

  IF c_StudyTbl%ISOPEN
  THEN
     CLOSE c_StudyTbl;
  END IF;
EXCEPTION
  WHEN NO_DATA_FOUND
  THEN
     NULL;
END;
END my_package;
/

Answer 1:

你需要使用对象构造上的选择:

SELECT OBJTYP(A, B, C)
   FROM my_table
  WHERE Study_Number = p_StudyNum(i)

但可以简化程序,这不是所有的循环:

begin
select cast(multiset(select /*+ cardinality(s, 10) */ a, b, c
                        from my_table t, table(p_StudyNum) s
                      where t.study_number = s.column_value) as OutputTyp)
   into p_StdyDtl
   from dual;
end;


Answer 2:

尝试宣告你的光标为:

CURSOR c_StudyTbl
IS
  SELECT OBJTYP(A, B, C)
    FROM my_table
    WHERE Study_Number = p_StudyNum(i);


文章来源: PLS-00386: type mismatch found between FETCH cursor and INTO variables