title: How can one programmatically find the current Oracle patch set?
body: <p>In <a href="http://docs.oracle.com/cd/B28359_01/server.111/b28310/dba004.htm#ADMIN11032"><em>Identifying Your Oracle Database Software Release</em></a> Oracle states that you can find your "platform-specific release number" (patch set)  by querying <a href="http://docs.oracle.com/cd/E11882_01/server.112/e40402/statviews_5153.htm#REFRN29037">PRODUCT_COMPONENT_VERSION</a>:</p>
  
  <blockquote>
    <p>To identify the release of Oracle Database that is currently installed and to see the release levels of other database components you are using, query the data dictionary view PRODUCT_COMPONENT_VERSION.</p>
  </blockquote>
  
  <p>According to this we are using 11.2.0.3.0</p>
  
  <pre><code>SQL&gt; select * from product_component_version;
  
  PRODUCT                             VERSION         STATUS
  ----------------------------------- --------------- ---------------
  NLSRTL                              11.2.0.3.0      Production
  Oracle Database 11g                 11.2.0.3.0      64bit Production
  PL/SQL                              11.2.0.3.0      Production
  TNS for Linux:                      11.2.0.3.0      Production
  </code></pre>
  
  <p>The same occurs with V$VERSION (which PRODUCT_COMPONENT_VERSION is a view of incidentally):</p>
  
  <pre><code>SQL&gt; select * from v$version;
  
  BANNER
  ---------------------------------------------------------
  
  Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
  PL/SQL Release 11.2.0.3.0 - Production
  CORE    11.2.0.3.0      Production
  TNS for Linux: Version 11.2.0.3.0 - Production
  NLSRTL Version 11.2.0.3.0 - Production
  </code></pre>
  
  <p>However, according to <a href="http://docs.oracle.com/cd/E11882_01/server.112/e40402/statviews_4211.htm#REFRN23549">DBA_REGISTRY_HISTORY</a> the database appears to be on 11.2.0.3.5<sup>1</sup>:</p>
  
  <pre><code>SQL&gt; select action, namespace, version, id, comments from dba_registry_history;
  
  ACTION          NAMESPACE VERSION            ID COMMENTS
  --------------- --------- ---------- ---------- ------------------------------
  VIEW INVALIDATE                         8289601 view invalidation
  UPGRADE         SERVER    11.2.0.3.0            Upgraded from 11.2.0.1.0
  APPLY           SERVER    11.2.0.3            0 Patchset 11.2.0.2.0
  APPLY           SERVER    11.2.0.3            5 PSU 11.2.0.3.5
  </code></pre>
  
  <p>DBA_REGISTRY_HISTORY doesn't necessarily have any data in it so I can't reliably use this view. And, Oracle doesn't seem to provide a standardised method of populating the comments field I seem to be left doing the following and then praying that it works.</p>
  
  <pre><code>select max(regexp_replace(comments, '[^[:digit:].]')) 
           keep (dense_rank first order by action_time desc)
    from dba_registry_history
  </code></pre>
  
  <p>Is there an easier, reliable, method of finding out the current version, including patch set, programmatically?</p>
  
  <p><sub>1. Also possible: I'm completely misreading this and people have forgotten what they patched.</sub></p>