0

有这个包,我正在尝试使用下面的代码执行。但是我收到一个错误

ORA-06530: 对未初始化复合的引用

代码:

DECLARE
   StudyNum    InputTyp := InputTyp ();
   StudyDetails   OutputTyp := OutputTyp ();
BEGIN
   StudyNum.EXTEND;
   StudyNum (1) := '9071';
   my_package.my_procedure(StudyNum, StudyDetails);
END;
/

该包创建如下,用户定义的数据类型作为输入和输出参数:

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 OUT OutputTyp);
END my_package;
/
CREATE OR REPLACE PACKAGE BODY my_package
AS
   PROCEDURE my_procedure(p_StudyNum IN InputTyp,p_StdyDtl OUT 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;
/
4

1 回答 1

1

你要么需要做:

p_StdyDtl(p_StdyDtl.last) := OBJTYP(null, null, null);
p_StdyDtl (j).A := v_StudyTbl.A;
p_StdyDtl (j).B := v_StudyTbl.B;
p_StdyDtl (j).C := v_StudyTbl.C;

或更简单:

p_StdyDtl(j) := OBJTYP(v_StudyTbl.A, v_StudyTbl.B, v_StudyTbl.C);

您的代码原样失败,因为您已初始化OutputTyp但未初始化objtyp部分。

但正如我在你之前的问题中所说的那样,multiset避免了所有这些。

于 2013-03-19T22:12:36.243 回答