ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Purpose
Specifies the Oracle version numbers and other information useful for simple conditional compilation selections based on Oracle versions.
<vi> has the form of an unquoted PL/SQL identifier. It is unrestricted and can be a reserved word or a keyword. The text is insensitive to case. Each one is known as a flag or flag name.
Each <vi> can occur more than once in the string, each occurrence can have a different flag value, and the flag values can be of different kinds.
<ci> is one of the following: a PL/SQL boolean literal, a PLS_INTEGER literal, or the literal NULL. The text is insensitive to case. Each one is known as a flag value and corresponds to a flag name.
You can define any allowable value for PLSQL_CCFLAGS. However, Oracle recommends that this parameter be used for controlling the conditional compilation of debugging or tracing code. It is recommended that the following identifiers not be used as flag name values:
Names of Oracle parameters (for example, NLS_LENGTH_SEMANTICS)
Identifiers with any of the following prefixes: PLS_, PLSQL_, PLSCC_, ORA_, ORACLE_, DBMS_, SYS_
CREATE OR REPLACE PROCEDURE whetstone AUTHID DEFINER IS
-- Notice that conditional compilation constructs can interrupt a regular PL/SQL statement.
-- You can locate a conditional compilation directive anywhere there is whitespace in the regular statement.
SUBTYPE my_real IS
$IF DBMS_DB_VERSION.VER_LE_11 $THEN
NUMBER
$ELSE
BINARY_DOUBLE
$END;
-- procedure nested inside whetstone
PROCEDURE P(x my_real, y my_real, z OUT NOCOPY my_real) AUTHID DEFINER IS
x1 my_real;
y1 my_real;
BEGIN
x1 := x;
y1 := y;
x1 := t * (x1 + y1);
y1 := t * (x1 + y1);
z := (x1 + y1)/t2;
END P;
BEGIN
P(x, y, z);
dbms_output.put_line('z = '|| z);
END whetstone;
/
PL/SQL Code
set serveroutput on
BEGIN
$IF dbms_db_version.ver_le_10 $THEN
dbms_output.put_line('version 10g or earlier code');
$ELSIF dbms_db_version.ver_le_11 $THEN
dbms_output.put_line('version 11g code');
$ELSE
dbms_output.put_line('version 12c code');
$ELSE
dbms_output.put_line('version 18c or later code');
$END -- note that there is no semi-colon
END;
/
PL/SQL Code
CREATE OR REPLACE FUNCTION myfunc RETURN VARCHAR2 AUTHID DEFINER IS
BEGIN
$IF $$ppval $THEN
RETURN 'PPVAL was TRUE';
$ELSE
RETURN 'PPVAL was FALSE';
$END -- note that there is no semi-colon
END myfunc;
/
SELECT myfunc FROM dual;
ALTER SESSION SET plsql_ccflags = 'PPVAL:TRUE';
SELECT myfunc FROM dual;
ALTER FUNCTION myfunc COMPILE;
ALTER SESSION SET plsql_ccflags = 'PPVAL:FALSE';
SELECT myfunc FROM dual;
ALTER FUNCTION myfunc COMPILE
plsql_ccflags = 'PPVAL:TRUE'
REUSE SETTING;
Debug Demo
set serveroutput on
CREATE OR REPLACE PACKAGE debug_pkg AUTHID DEFINER IS
debug_flag CONSTANT BOOLEAN := FALSE;
END;
/
CREATE OR REPLACE PROCEDURE myproc IS
BEGIN
$IF debug_pkg.debug_flag $THEN
dbms_output.put_line('Debug=T');
$ELSE
dbms_output.put_line('Debug=F');
$END -- note that there is no semi-colon
END myproc;
/