title: Oracle object array initialization collection
body: <p>I am trying to create an array of oracle object type and I am getting some initialization related error.</p>
  
  <p>Below is the sample code</p>
  
  <pre><code>CREATE OR REPLACE TYPE rectangle AS OBJECT
  (
  -- The type has 3 attributes.
    length NUMBER,
    width NUMBER,
    area NUMBER,
  -- Define a constructor that has only 2 parameters.
    CONSTRUCTOR FUNCTION rectangle(length NUMBER, width NUMBER)
      RETURN SELF AS RESULT
  );
  
  CREATE OR REPLACE TYPE BODY rectangle AS
    CONSTRUCTOR FUNCTION rectangle(length NUMBER, width NUMBER)
      RETURN SELF AS RESULT
    AS
    BEGIN
      SELF.length := length;
      SELF.width := width;
  
      SELF.area := length * width;
      RETURN;
    END;
  END;
  </code></pre>
  
  <p>To run below is the sample script</p>
  
  <pre><code>set serveroutput on
  DECLARE
    r1 rectangle;
    r2 rectangle;
    type rect_arr is table of rectangle;
    m_rect  rect_arr;
  BEGIN
    m_rect.extend;
    m_rect(1) := rectangle(10,20);
    sop(m_rect(1).area);  
  END;
  </code></pre>
  
  <p>Below is the error on console----- I know it is related to initialization error, and tried various constructor and member function solutions but none help.</p>
  
  <p>Error report:
  <strong>ORA-06531: Reference to uninitialized collection
  ORA-06512: at line 7</strong>
  06531. 00000 -  "Reference to uninitialized collection"
  *Cause:    An element or member function of a nested table or varray
             was referenced (where an initialized collection is needed)
             without the collection having been initialized.
  *Action:   Initialize the collection with an appropriate constructor
             or whole-object assignment.</p>