Wednesday, October 8, 2014

ORA-06530: Reference to uninitialized composite

CREATE OR REPLACE TYPE XX_QP_PRICE_MOD_OBJ_TYPE
IS
  OBJECT
  (
    modifier_name        VARCHAR2 (240),
    modifier_description VARCHAR2 (240),
    adjustment_amount    NUMBER );

CREATE OR REPLACE TYPE xx_qp_price_mod_tbl_type IS VARRAY (1000) OF XX_QP_PRICE_MOD_OBJ_TYPE ;


SET SERVEROUTPUT ON
DECLARE
  v_mod_tbl xx_qp_price_mod_tbl_type := xx_qp_price_mod_tbl_type();
  i         NUMBER                           :=1;
  V_MOD_IDX NUMBER                           := 1;
BEGIN
  LOOP
    v_mod_tbl.extend();
    v_mod_tbl(v_mod_idx).adjustment_amount := 100;
    v_mod_tbl(v_mod_idx).modifier_name     := 200;
    v_mod_idx                              := v_mod_idx + 1;
    EXIT
  WHEN i=5;
    i  := i + 1;
  END LOOP;
EXCEPTION
WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;


Output :
anonymous block completed
ORA-06530: Reference to uninitialized composite




Solution:

SET SERVEROUTPUT ON
DECLARE
  v_mod_tbl xx_qp_price_mod_tbl_type := xx_qp_price_mod_tbl_type();
  i         NUMBER                           :=1;
  V_MOD_IDX NUMBER                           := 1;
BEGIN
  LOOP
    v_mod_tbl.extend();
    v_mod_tbl(v_mod_idx).adjustment_amount := 100;
    v_mod_tbl(v_mod_idx).modifier_name     := 200;
    v_mod_tbl(v_mod_tbl.last) := XX_QP_PRICE_MOD_OBJ_TYPE(NULL,NULL,NULL);
    v_mod_idx                              := v_mod_idx + 1;
    EXIT
  WHEN i=5;
    i  := i + 1;
  END LOOP;
EXCEPTION
WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
Reactions:

0 comments:

Post a Comment