title: What is this Oracle code doing?
body: <p>I found this article on the Oracle site: <a href="http://www.oracle.com/technetwork/issue-archive/o33plsql-083386.html" rel="nofollow">Managing Exceptional Behavior, Part 1</a>.</p>
  
  <p>In it, someone had defined an error package, with procedures to raise, handle, report and go, report and stop and log. A breakdown of this package can be found here: <a href="http://www.oracle.com/technetwork/issue-archive/errpkg-pkg-102717.html" rel="nofollow">errpkg</a>.</p>
  
  <p>The part I'm interested in is here:</p>
  
  <pre><code>IF l_errcode BETWEEN -20999 AND -20000 THEN
      raise_application_error (l_errcode, l_errmsg);
  /* Use positive error numbers -- lots to choose from! */
  ELSIF l_errcode &gt; 0 AND l_errcode NOT IN (1, 100) THEN
      raise_application_error (-20000, l_errcode || '-' || l_errmsg);
  /* Can't EXCEPTION_INIT -1403 */
  ELSIF l_errcode IN (100, -1403) THEN
      RAISE NO_DATA_FOUND;
  /* Re-raise any other exception. */
  ELSIF l_errcode != 0 THEN
      EXECUTE IMMEDIATE
          'DECLARE myexc EXCEPTION; ' ||
          '   PRAGMA EXCEPTION_INIT (myexc, ' || TO_CHAR (err_in) || ');' ||
          'BEGIN  RAISE myexc; END;';
  END IF;
  </code></pre>
  
  <p>That snippet has been pasted in exactly as it appears in the article. I <em>believe</em> that the first <code>if</code> statement is covering all user errors, as -209999 to -20000 is reserved for user created exceptions.</p>
  
  <p>In the first <code>elsif</code> statement (errcode > 0 and not in (1,00)), the code, according to the article, is doing the following:</p>
  
  <blockquote>
    <p>I also handle positive numbers for application-specific error
    numbers. By handling positive error message numbers, I am not
    constrained to error numbers between -20,999 and -20,000, some of
    which Oracle also uses (although I stay away from 1 and 100, the only
    two positive error numbers that Oracle does use).</p>
  </blockquote>
  
  <p>So to me that sounds like he is happy with declaring errors in his code like 150, 160, 170 etc, provided they don't occur between 1 and 100.</p>
  
  <p>However, what are the next two parts of the procedure doing? What is the errcode in (100, -1403) for? I can see it's to do with error code 01403 (no data found), but I don't understand its position in the brackets (100, -1403). And what is the final elsif that does an execute immediate for? I'm struggling to see what its purpose is.</p>