title: Why is this check for null associative array in PL/SQL failing?
body: <p>I have an associative array created by a type of rowtype of a table column. </p>
  
  <p>To give an example, this is how it is(the table names are different, but the structure is the same):</p>
  
  <p>This is the DDL of the table</p>
  
  <pre><code>CREATE TABLE employees
    (
       id     NUMBER,
       name   VARCHAR2(240),
       salary NUMBER
    ); 
  </code></pre>
  
  <p>Here's what my procedure is doing:</p>
  
  <pre><code>DECLARE
      TYPE table_of_emp
        IS TABLE OF employees%ROWTYPE INDEX BY BINARY_INTEGER;
      emp TABLE_OF_EMP;
  BEGIN
      IF emp IS NULL THEN
        dbms_output.Put_line('Null associative array');
      ELSE
        dbms_output.Put_line('Not null');
      END IF;
  END; 
  </code></pre>
  
  <p>I assume this <em>should</em> result in "Null associative array" being printed. However, the <code>if</code> condition fails and the execution jumps to the else part.</p>
  
  <p>Now if I put in a <code>for</code> loop to print the collection values</p>
  
  <pre><code>DECLARE
      TYPE table_of_emp
        IS TABLE OF employees%ROWTYPE INDEX BY BINARY_INTEGER;
      emp TABLE_OF_EMP;
  BEGIN
      IF emp IS NULL THEN
        dbms_output.Put_line('Null associative array');
      ELSE
        dbms_output.Put_line('Not null');
  
        FOR i IN emp.first..emp.last LOOP
            dbms_output.Put_line('Emp name: '
                                 || Emp(i).name);
        END LOOP;
      END IF;
  END; 
  </code></pre>
  
  <p>then the program unit raises an exception, referencing the for loop line </p>
  
  <blockquote>
    <p>ORA-06502: PL/SQL: Numeric or value error</p>
  </blockquote>
  
  <p>which I presume is because of the null associative array. Is the error being raised because of null associative array?</p>
  
  <p>So why is the first check failing then? What am I doing wrong?</p>
  
  <p>The database server is Oracle 11g EE (version 11.2.0.3.0 64 bit)</p>