Home » SQL & PL/SQL » SQL & PL/SQL » ORA-06531: Reference to uninitialized collection (Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit,OS: XP Window )
ORA-06531: Reference to uninitialized collection [message #578556] Fri, 01 March 2013 03:54 Go to next message
chandan.rattan
Messages: 84
Registered: December 2008
Location: India
Member

HI,
I am getting the error ORA-06531: Reference to uninitialized collection while calling a table function which is of collection type.
CREATE OR REPLACE FUNCTION FN_GET_LINK_SYS_ID
  RETURN PGIPK_DM_PROCESS.DM_SYSID
  PIPELINED IS
  T_SYS_ID PGIPK_DM_PROCESS.DM_SYSID;
BEGIN

  T_SYS_ID := PGIPK_DM_PROCESS.DM_SYSID();

  FOR I IN 1 .. PGIPK_DM_PROCESS.DM_SYS_ID.COUNT LOOP
    T_SYS_ID.EXTEND(I);
    T_SYS_ID(I) := PGIPK_DM_PROCESS.DM_SYS_ID(I);
    PIPE ROW(T_SYS_ID(I));
  END LOOP;
  RETURN;
END;


Definition of Type is below

--NESTED TABLE TO STORE SYS_ID S OF TABLE 
  TYPE TAB_SYS_ID IS RECORD(
    POL_NO              VARCHAR2(60),
    POL_END_NO_IDX      NUMBER,        
    PSEC_SEC_CODE       VARCHAR2(30),    
    PRAI_RISK_ID        VARCHAR2(10),
    PRC_CODE            VARCHAR2(60),    
    SMI_CODE            VARCHAR2(60),
    PSEC_SYS_ID         NUMBER,
    POL_SYS_ID          NUMBER,    
    PRAI_SYS_ID         NUMBER,
    PRC_SYS_ID          NUMBER,
    SMI_SYS_ID          NUMBER);

  TYPE DM_SYSID IS TABLE OF TAB_SYS_ID;
  DM_SYS_ID DM_SYSID;


when i m writing select * from table(FN_GET_LINK_SYS_ID) , its throwing ORA-06531: Reference to uninitialized collection


[EDITED by LF: fixed [code] tags]

[Updated on: Fri, 01 March 2013 04:17] by Moderator

Report message to a moderator

Re: ORA-06531: Reference to uninitialized collection [message #578557 is a reply to message #578556] Fri, 01 March 2013 03:57 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
That'd be because of this:
PGIPK_DM_PROCESS.DM_SYS_ID.COUNT 

Not sure what you think the count of a table type is going to be.
Re: ORA-06531: Reference to uninitialized collection [message #578559 is a reply to message #578557] Fri, 01 March 2013 04:02 Go to previous messageGo to next message
chandan.rattan
Messages: 84
Registered: December 2008
Location: India
Member

I missed out one piece of code

----------
------------
  IDX := IDX + 1;
    
      DM_SYS_ID.EXTEND(1);
    
      DM_SYS_ID(IDX).POL_NO := M_POL_NO;
      DM_SYS_ID(IDX).POL_END_NO_IDX := M_END_NO_IDX;
      DM_SYS_ID(IDX).PSEC_SEC_CODE := M_SEC_CODE;
      DM_SYS_ID(IDX).PRAI_RISK_ID := M_RISK_ID;
      DM_SYS_ID(IDX).PRC_CODE := M_CVR_CODE;
      DM_SYS_ID(IDX).SMI_CODE := M_SMI_CODE;
      DM_SYS_ID(IDX).PSEC_SYS_ID := NULL;
      DM_SYS_ID(IDX).POL_SYS_ID := NULL;
      DM_SYS_ID(IDX).PRAI_SYS_ID := NULL;
      DM_SYS_ID(IDX).PRC_SYS_ID := NULL;
      DM_SYS_ID(IDX).SMI_SYS_ID := NULL;

------------

THEN HERE CALLING SELECT * FROM TABLE(FN_GET_LINK_SYS_ID) 
----------
Re: ORA-06531: Reference to uninitialized collection [message #578560 is a reply to message #578557] Fri, 01 March 2013 04:07 Go to previous messageGo to next message
chandan.rattan
Messages: 84
Registered: December 2008
Location: India
Member

cookiemonster wrote on Fri, 01 March 2013 09:57
That'd be because of this:
PGIPK_DM_PROCESS.DM_SYS_ID.COUNT 

Not sure what you think the count of a table type is going to be.



its methods of Collection and it will work.
Re: ORA-06531: Reference to uninitialized collection [message #578562 is a reply to message #578556] Fri, 01 March 2013 04:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You wrongly write a pipelined function.
Please search in this forum you will have many examples.
For instance, a simple one there.

Regards
Michel
Re: ORA-06531: Reference to uninitialized collection [message #578564 is a reply to message #578562] Fri, 01 March 2013 04:53 Go to previous messageGo to next message
chandan.rattan
Messages: 84
Registered: December 2008
Location: India
Member

Pipeline function is fine only.Now i solved the problem.I didn't assign the values into dm_sys_id's elements properly, hence that was coming.But now i am getting different error.
Re: ORA-06531: Reference to uninitialized collection [message #578568 is a reply to message #578564] Fri, 01 March 2013 05:24 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Pipeline function is fine only.


From what you posted, yOu are wrong.

Quote:
now i am getting different error.


So fix it.

Regards
Michel
Previous Topic: Procedure execution takes more time. Need help
Next Topic: What is the scenario for not possible to create index for the table?
Goto Forum:
  


Current Time: Thu Apr 25 21:23:53 CDT 2024