Kyle H
Kyle H

Reputation: 3295

PL/SQL - conditional compilation specific to one database

I have an Oracle development database that has some packages that end up getting copied to production servers. I'm looking for a way to use conditional compilation in the package spec that is only true on this one development server, but compiles to false on all other servers.

I can't add anything to the Production servers to accomplish this - no new global variable/config settings/procedures/etc.

So is there a way to effectively do

$IF {{development_server}} $THEN
    my_proc;
$END

Upvotes: 3

Views: 902

Answers (2)

Steven Feuerstein
Steven Feuerstein

Reputation: 1974

I am not sure if this is precisely what you are after, but it should give you something to work with:

CREATE OR REPLACE PACKAGE my_app_state
   AUTHID DEFINER
IS
   c_in_production   CONSTANT BOOLEAN := TRUE;
END;
/

CREATE OR REPLACE PROCEDURE test_app_state
   AUTHID DEFINER
IS
   PROCEDURE my_proc1 
   IS
   BEGIN
      DBMS_OUTPUT.PUT_LINE ('1');
   END;

   PROCEDURE my_proc2
   IS
   BEGIN
      DBMS_OUTPUT.PUT_LINE ('2');
   END;
BEGIN
   $if my_app_state.c_in_production $then
      my_proc1;
   $else
      my_proc2;
   $end
end;
/

EXEC test_app_state

You can also use a conditional compilation flag. If it is undefined, it simply defaults to NULL, so the default production state of affairs is "off".

CREATE OR REPLACE PROCEDURE test_app_state
   AUTHID DEFINER
IS
   PROCEDURE my_proc1 
   IS
   BEGIN
      DBMS_OUTPUT.PUT_LINE ('1');
   END;

   PROCEDURE my_proc2
   IS
   BEGIN
      DBMS_OUTPUT.PUT_LINE ('2');
   END;
BEGIN
   $if $$cc_in_dev $then
      my_proc1;
   $else
      my_proc2;
   $end
end;
/

Upvotes: 4

JDro04
JDro04

Reputation: 670

v$database has the database name in it. If they're named differently this should work.

SELECT NAME FROM v$database;

Upvotes: 0

Related Questions