Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a way to do this, providing you are on 10g or higher. It's called Conditional Compilation. This is a highly neat feature which provides special syntax so we can change our PL/SQL code at compilation time.</p> <p>As it happens I have been using this feature precisely to expose private packages in a spec so I can run UTPLSQL tests against them.</p> <p>Here is the special syntax:</p> <pre><code>create or replace package my_pkg as $IF $$dev_env_test $THEN PROCEDURE private_proc; $END FUNCTION public_function return date; end my_pkg; / </code></pre> <p>That variable with the double-dollar sign is a Conditional Compilation flag.</p> <p>If I describe the package we can only see the public package: </p> <pre><code>SQL&gt; desc my_pkg FUNCTION PUBLIC_FUNCTION RETURNS DATE SQL&gt; </code></pre> <p>Now I set the conditional flag and re-compile the package, and as if by magic ...</p> <pre><code>SQL&gt; alter session set plsql_ccflags='dev_env_test:true' 2 / Session altered. SQL&gt; alter package my_pkg compile 2 / Package altered. SQL&gt; desc my_pkg PROCEDURE PRIVATE_PROC FUNCTION PUBLIC_FUNCTION RETURNS DATE SQL&gt; </code></pre> <p>Privatising the functions is as simple as you think it would be: </p> <pre><code>SQL&gt; alter session set plsql_ccflags='dev_env_test:false' 2 / Session altered. SQL&gt; alter package my_pkg compile 2 / Package altered. SQL&gt; desc my_pkg FUNCTION PUBLIC_FUNCTION RETURNS DATE SQL&gt; </code></pre> <p>We can do lots more with conditional compilation. It's covered in the docs. <a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/fundamentals.htm#BABIHIHF" rel="noreferrer">Find out more.</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload