Conditional logic in a main SQLPLUS script file

From: Dylan Farre <dylan.farre_at_gmail.com>
Date: Wed, 5 Jan 2011 11:12:45 +0000
Message-ID: <AANLkTi=7KNQOfeRDhG5o=_UOWOAmpzYN80HzcfoL8SDf_at_mail.gmail.com>



I am looking for a way to implement conditional logic in a main sql script file, that calls other script files.

In PLSQL, this is easy using regular IF THEN ELSE statements. It is even easy to add or remove blocks of PLSQL from compiled objects (using pre-compiler directives). For example, in a stored procedure, by including something like this:

CREATE OR REPLACE PROCEDURE ZZZ AS
..

BEGIN   $IF packageA.option_1 = 1 $THEN
    do_something();
  $ELSE
    do_something_else();
  $END END;
/

Which will create two different versions of procedure ZZZ, depending on the value of packageA.option_1. Sometimes this is handy, if most of the code in procedure ZZZ is the same and there is only a small difference required under certain circumstances.

But what I want to do is something like this:

_at_script_0.sql
$IF packageA.option_1 = 1 $THEN

    _at_script_1.sql
$ELSE

    _at_script_2.sql
$END

...

I understand that this does not work, but is there a another way to achieve what I am trying to do here?

Any suggestions? Thanks.

--
http://www.freelists.org/webpage/oracle-l
Received on Wed Jan 05 2011 - 05:12:45 CST

Original text of this message