With the DBMS_UTILITY.DB_VERSION procedure, which returns database version information.
This question caused me a bit of grief.
I had been writing a procedure to drop a users objects, so that developers could just clean out everything owned by a user without doing DROP USER and CREATE USER. After all, who wants to give developers the DROP USER privilege? Anyway, after spending a while sidetracked with SYS_CONTEXT function and the USERENV context, which would seem to be the logical place to find the database version detail, I eventually stumbled on to DBMS_UTILITY.DB_VERSION.
The following simple example program in PL/SQL demonstrates how to get the database version using PL/SQL.
using DBMS_UTILITY.DB_VERSION shows how the version and compatibility can be found.
SET SERVEROUTPUT ONDECLARE
DBMS_UTILITY.db_version (version => l_version,
compatibility => l_compatibility);
DBMS_OUTPUT.put_line('Version: ' || l_version || ' Compatibility: ' || l_compatibility);
anonymous block completed
Version: 220.127.116.11.0 Compatibility: 8.1.7