Skip to main content
← PL/SQL Topics

Advanced & Performance

Explain conditional compilation with $IF, $ELSE and $ERROR

Conditional Compilation

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

Preprocessor directives choose which code to compile based on flags, DB version, or static package constants.

How it works

Conditional compilation directives ($IF ... $THEN ... $ELSIF ... $ELSE ... $END) are evaluated at compile time. Conditions use inquiry directives ($$flag, set via PLSQL_CCFLAGS or ALTER), DBMS_DB_VERSION constants, or static package constants. $ERROR raises a compile-time error. Typical uses: leave instrumentation/logging in the source but compile it out of production, or maintain one code base across DB versions. Check the result with DBMS_PREPROCESSOR.PRINT_POST_PROCESSED_SOURCE.

How it works
ALTER SESSION SET PLSQL_CCFLAGS = 'debug_on:true';

CREATE OR REPLACE PROCEDURE do_work AS
BEGIN
  $IF $$debug_on $THEN
    DBMS_OUTPUT.PUT_LINE('DEBUG: entering do_work at ' || SYSTIMESTAMP);
  $END

  $IF DBMS_DB_VERSION.VERSION < 12 $THEN
    $ERROR 'This procedure requires Oracle 12c or later' $END
  $END
  NULL;
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI