pl/sql object types "ORA-06530: Reference to uninitialized composite" error
I reproduced the same behaviour in Oracle 11gR1. I would agree with you, this seems like a bug to me too, albeit a trivial one.
SQL> CREATE OR REPLACE TYPE tbusiness_inter_item_bag AS OBJECT ( 2 item_id NUMBER(1), 3 system_event_cd VARCHAR2 (20), 4 CONSTRUCTOR FUNCTION tbusiness_inter_item_bag RETURN SELF AS RESULT 5 ); 6 /Type created.SQL> DECLARE 2 item tbusiness_inter_item_bag; 3 BEGIN 4 item.item_id := 1; 5 END; 6 /PL/SQL procedure successfully completed.SQL>
Note that this still fails:
SQL> DECLARE 2 item tbusiness_inter_item_bag; 3 BEGIN 4 item.item_id := 1; 5 item.system_event_cd := 'ABC'; 6 END; 7 /DECLARE*ERROR at line 1:ORA-06530: Reference to uninitialized compositeORA-06512: at line 5SQL>
Obviously, the correct practice is always initialize objects before referencing them.
SQL> DECLARE 2 item tbusiness_inter_item_bag := tbusiness_inter_item_bag(); 3 BEGIN 4 item.system_event_cd := 'ABC'; 5 END; 6 /PL/SQL procedure successfully completed.SQL>
You need to call the constructor you defined:
SQL> DECLARE 2 item tbusiness_inter_item_bag := tbusiness_inter_item_bag(); 3 /* ^^ call the constructor */ 4 BEGIN 5 item.system_event_cd := 'ABC'; 6 END; 7 /PL/SQL procedure successfully completed
I observe the behaviour you described on a 10.2.0.3 database. I wouldn't rely on it though, it looks like a bug.
I dont think its bug. As per documentation, you are supposed to initialize the composite type. This will always work :SQL> DECLARE2 item tbusiness_inter_item_bag := tbusiness_inter_item_bag();3 BEGIN4 item.system_event_cd := 'ABC';5 END;6 /
PL/SQL procedure successfully completed.
SQL>