0

不知道是什么导致了这个错误。I 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: Reference to uninitialized composition

请帮忙。

4

1 回答 1

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);

于 2012-12-12T15:30:30.823 回答