NULL index table key value error raised only at first run of statement
<p>I have a view on two different schemas described by this code:</p>

<pre><code>CREATE OR REPLACE VIEW LINKTYPE AS
SELECT LINKTYPEID
,      nvl((select value from translation where translation2dimobject = 14 and objectid = linktypeid and columnid = 1 and localeid = SYS_CONTEXT('CRAMERSESSION', 'LOCALEID')), NAME) NAME
,      LINKTYPE2GRAPHICSBITMAP
,      LINKTYPE2BROWSERBITMAP
,      TABLENAME
,      nvl((select value from translation where translation2dimobject = 14 and objectid = linktypeid and columnid = 2 and localeid = SYS_CONTEXT('CRAMERSESSION', 'LOCALEID')), CLASS) CLASS
,      nvl((select value from translation where translation2dimobject = 14 and objectid = linktypeid and columnid = 3 and localeid = SYS_CONTEXT('CRAMERSESSION', 'LOCALEID')), DESCRIPTION) DESCRIPTION
,      RESOLUTIONBEHAVIOUR
,      LENGTHCALLOUT
,      ISVISIBLE
,      LABEL
from   LINKTYPE_M with read only;
</code></pre>

<p>Then I'm calling this function from both schemas:</p>

<pre><code>FUNCTION getLinkTypeID (pis_link_type_name LINKTYPE.NAME%TYPE)
RETURN NUMBER IS

   ln_link_type_ID NUMBER;

BEGIN

BEGIN
   SELECT linktypeid
   INTO ln_link_type_ID
   FROM CRAMER.LINKTYPE lnt
   WHERE lnt.NAME = pis_link_type_name;

   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         ln_link_type_ID := null;
END;

   RETURN ln_link_type_ID;

END getLinkTypeID;
</code></pre>

<p>like this:</p>

<pre><code>declare
ln_link_type_ID number;

    begin
      ln_link_type_ID := customisations.nr_links_validations.getLinkTypeID('test');
      dbms_output.put_line(ln_link_type_ID);
      end;
</code></pre>

<p>No matter the parameter given to the function from one of the schemas I get the </p>

<blockquote>
  <p>NULL index table key value</p>
</blockquote>

<p>error but only at first run, from the other schema I don't have this problem. I need to mention that the schemas are a little different but the part with above view, function and call of the function is identical.
Have anyone had this kind of issue or have any idea why this error appears?</p>

<p>The stack trace shows that the error is raised from here   </p>

<pre><code>FOR rec IN (SELECT DISTINCT NODETYPEID FROM LINKPORTVALIDATION) LOOP
      gr_nodetypes_vld(rec.NODETYPEID) := 1; --this line
   END LOOP;
</code></pre>

<p>and gr_nodetypes_vld is declare in the body section and not in the specification:</p>

<pre><code>TYPE gt_nodetypes_vld IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
gr_nodetypes_vld  gt_nodetypes_vld;
</code></pre>

<p>I think this is the initialisation section</p>

<pre><code>BEGIN
   --First-time code. Executed once per session =&gt; Performance
   --Fill an array of all nodetypes tracked by the validation table.
   --All unique nodetypes in there will be checked against their link types.
   --All other nodetypes are not validated at all
   gr_nodetypes_vld.DELETE;
   FOR rec IN (SELECT DISTINCT NODETYPEID FROM LINKPORTVALIDATION) LOOP
      gr_nodetypes_vld(rec.NODETYPEID) := 1;
   END LOOP;

   gr_cardtypes_vld.DELETE;
   FOR rec IN (SELECT DISTINCT NODETYPEID||'.'||CARDTYPEID NODECARD_TYPE
               FROM LINKPORTVALIDATION
               WHERE CARDTYPEID IS NOT NULL
               ORDER BY 1) LOOP
      gr_cardtypes_vld(rec.NODECARD_TYPE) := 1;
   END LOOP;
END NR_LINKS_VALIDATIONS;
</code></pre>