My issue with the "my_pkg" above was in development and in qa. There could be many schemas, but only 2 applications. APP_A and APP_B. In qa schema names might be: qa_app_a_1, qa_app_a_2, qa_app_a_3 and qa_app_b_1, qa_app_a_b, qa_app_b_3 where there are 3 environments for app_a and 3 for app_b. My original approach had an "IN" clause for each app.
SYS_CONTEXT ('userenv', 'current_schema')
in ('APP-A','APP-A-QA1','APP-A-QA2','APP-A-DEV1')
I do not see a way to do this inside of the db with out on the fly processing.
This will not work:
CREATE OR REPLACE package which_app
$IF SYS_CONTEXT ('userenv', 'current_schema')
in ('APP-A','APP-A-QA1','APP-A-QA2','APP-A-DEV1') $THEN
app CONSTANT VARCHAR (10) := 'APP-A';
$ELSE
app CONSTANT VARCHAR (10) := 'APP-B';
$END
END;
Currently all my database builds are shell scripts so my workaround is to have the shell script to parse the package and compile it on each install with a hard coded app constant.
CREATE OR REPLACE package which_app
app CONSTANT VARCHAR (10) := 'APP-A';
END;
BTW, 99.99% of the code for the 2 apps is the same, I have 1 formula that is different. But gets hit 1000s of times a day.