执行过程时出错:ORA-06530:引用未初始化的复合

时间:2012-12-12 14:57:17

标签: oracle plsql

不确定导致此错误的原因。一世 1)创建了一个对象

  CREATE OR REPLACE  TYPE opt_val_rec AS  OBJECT (
    parametervalue     VARCHAR2(1),
    PARAMETERID          varchar2(4000)
    );

2)已创建表格类型为

create  OR REPLACE  type  OPTVAL_TAB as  table of OPTVAL_REC;

3)写了一个程序

    Create or replace  procedure test_parm_val (id in varchar2 ,result out  varchar2) as
pos number:=0;
  test_paramval                                 OPTVAL_TAB:= OPTVAL_TAB (null);
paramval_ord   OPTVAL_TAB:= OPTVAL_TAB (null);


begin

for I in (select DISTINCT param_name from  param_tbl)
loop

test_paramval.extend(10);
POS :=POS+1;

test_paramval (POS).PARAMETERVALUE:= get_param_val_fnc(id,I.PARAM_NAME);
test_paramval(POS). parameterid:=I.PARAM_NAME;


End;

end test_parm_val

4)现在面临错误     ORA-06530:未初始化复合材料的参考

请帮忙。

1 个答案:

答案 0 :(得分:1)

尝试

 Create or replace  procedure test_parm_val 
      (id in varchar2 ,result out  varchar2) as

     pos number:=1; 
     test_paramval OPTVAL_TAB:= OPTVAL_TAB ();
     paramval_ord   OPTVAL_TAB:= OPTVAL_TAB ();
     new_record opt_val_rec ;

begin

for I in (select DISTINCT param_name from  param_tbl)
loop

  --test_paramval (POS).PARAMETERVALUE:= get_param_val_fnc(id,I.PARAM_NAME);
  --test_paramval(POS). parameterid:=I.PARAM_NAME;

 ----------------------------------------------------------------
 --  commented out, it will work if "opt_val_rec" was RECORD
 --  new_record.PARAMETERVALUE:= get_param_val_fnc(id,I.PARAM_NAME);
 --  new_record.parameterid:=I.PARAM_NAME;
 ----------------------------------------------------------------
  new_record = opt_val_rec (get_param_val_fnc(id,I.PARAM_NAME),I.PARAM_NAME);
  test_paramval.extend(1);
  test_paramval(POS) := new_record;
  POS :=POS+1;  -- not sure why you had 10, I guess it's a misprint
End;

end test_parm_val

更新抱歉,我没有意识到opt_val_rec是一个对象,而不是记录。您需要在循环中创建它的实例 new_record = opt_val_rec (get_param_val_fnc(id,I.PARAM_NAME),I.PARAM_NAME);