Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getting ORA-06531: Reference to uninitialized collection when running pl/sql block for extracting json array

Rahul BADec 13 2023

Hi all, I'm trying to run the below code and I'm getting ORA-06531: Reference to uninitialized collection error. I tried initializing the collection. But still, I'm getting the error.

DECLARE
V_JDOC_ARRAY JSON_ARRAY_T;
V_TEST2UUIDS JSON_OBJECT_T;
V_KEYS JSON_KEY_LIST;
v_cnt NUMBER;
BEGIN
V_JDOC_ARRAY := JSON_ARRAY_T ('[
{
"test1UUIDs": {},
"test2UUIDs": {
"1": "aaaaaa",
"2": "bbbbb"
}
},
{
"test1UUIDs": {},
"test2UUIDs": {}
}
]');

FOR V_I IN 0 .. V_JDOC_ARRAY.GET_SIZE - 1
LOOP
V_TEST2UUIDS :=
TREAT (
TREAT (V_JDOC_ARRAY.GET (V_I) AS JSON_OBJECT_T).GET (
'test2UUIDs')
AS JSON_OBJECT_T);
V_KEYS := V_TEST2UUIDS.GET_KEYS;
v_cnt := V_KEYS.COUNT; --where error is occurring
--V_KEYS := JSON_KEY_LIST ();
--FOR V_J IN 1..V_KEYS.COUNT LOOP
-- DBMS_OUTPUT.PUT_LINE('TEST2UUIDS(' || (V_I + 1) || '): ' || V_KEYS(V_J) || ' ' || V_TEST2UUIDS.GET_STRING(V_KEYS(V_J)));
--END LOOP;
END LOOP;
END;
/

Comments
Post Details
Added on Dec 13 2023
1 comment
738 views