I am using associative arrays in a package I am creating and I get the error ORA-06531: Reference to uninitialized collection if I try to get the count (TBL.COUNT) before I have bulk collected into the array.
I have found that I can use EXISTS(1) to check if there is something there instead of the count but if I am not bulk collecting into it, how do I get the index I need to use for the next row?
loc_idx := TBL.COUNT;
OR
TBL(TBL.COUNT+1) := blah;
My thought was that you didn't need to initialize associative arrays unlike Nested tables and varrays
Here is an example of one I am using
TYPE invc_ln_item_type IS TABLE OF invc_ln_item%ROWTYPE;
invc_ln_item_tbl invc_ln_item_type;
used as an input to the following proc
PROCEDURE CREATE_INVC_LN_ITEM(P_LN_ITEM_TYPE_CD IN
invc_ln_item.ln_item_type_cd%TYPE,
P_LN_ITEM_SBTYPE_CD IN
invc_ln_item.ln_item_sbtype_cd%TYPE,
P_INVC_PK IN invc.invc_pk%TYPE,
P_INVC_LN_ITEM_TBL IN OUT
invc_ln_item_type)
IS
loc_inv_ln_item_rec INVC_LN_ITEM%ROWTYPE;
loc_idx NUMBER;
BEGIN
loc_idx := P_INVC_LN_ITEM_TBL.COUNT + 1;
INSERT INTO APP.INVC_LN_ITEM (INVC_LN_ITEM_PK,
INSRT_DT,
INSRT_USER,
LAST_UPDT_DT,
LAST_UPDT_USER,
LN_ITEM_TYPE_CD,
LN_ITEM_SBTYPE_CD,
INVC_PK,
UNITS,
AMT)
VALUES (null,
null,
null,
null,
null,
P_LN_ITEM_TYPE_CD,
P_LN_ITEM_SBTYPE_CD,
P_INVC_PK,
0,
0)
RETURNING INVC_LN_ITEM_PK,
INSRT_DT,
INSRT_USER,
LAST_UPDT_DT,
LAST_UPDT_USER,
LN_ITEM_TYPE_CD,
LN_ITEM_SBTYPE_CD,
INVC_PK,
UNITS,
AMT
INTO loc_inv_ln_item_rec;
P_INVC_LN_ITEM_TBL(loc_idx) := loc_inv_ln_item_rec;
END;
Then gets called like
CREATE_INVC_LN_ITEM(P_BILLG_PRFL_LN_ITEM_REC.ln_item_type_cd,
billg_prfl_ln_item_sbtype_tbl(c).ln_item_sbtype_cd,
invc_rec.invc_pk,
invc_ln_item_tbl);
The errors in the case above occurs at: loc_idx := P_INVC_LN_ITEM_TBL.COUNT + 1;
[Error] Execution (39: 1): ORA-06531: Reference to uninitialized collection