Re: Conditional logic in a main SQLPLUS script file

From: Stephane Faroult <sfaroult_at_roughsea.com>
Date: Wed, 05 Jan 2011 12:23:18 +0100
Message-ID: <4D2454A6.4000707_at_roughsea.com>



The simples thing that comes to my mind is to add one script layer - generate your script from a script that includes some PL/SQL

Something such as

set feedback off
set trimspool on
set recsep off
set serveroutput on
spool main_script.sql
begin

   dbms_output.put_line('_at_scrip_0.sql');    if packageA.option_1 = 1
   then
     dbms_output.put_line('_at_script_1.sql');   else

     dbms_output.put_line('_at_script_2.sql');   end if;
end;
/
spool off
_at_main_script.sql

HTH Stephane Faroult
RoughSea Ltd <http://www.roughsea.com>
Konagora <http://www.konagora.com>
RoughSea Channel on Youtube <http://www.youtube.com/user/roughsealtd>

On 01/05/2011 12:12 PM, Dylan Farre wrote:
> 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:23:18 CST

Original text of this message