If you want to abandon the script entirely, you can do something like:
whenever sqlerror exit
select 1 / case when '&1' = 'PROD' then 0 else 1 end from dual;
whenever sqlerror continue
or if you want nice message
whenever sqlerror exit
begin
if '&1' = 'PROD' then
raise_application_error(-20000,'Not running in this PROD') ;
end if;
end;
/
whenever sqlerror continue
For portions of scripts, you can wrap the content in a PLSQL block and then dynamically set a comment flag, eg
define _ENV="--"
col env noprint new_value _ENV
select
case when '&1' = 'PROD' then '--' else '' end env
from
dual;
begin
null;
&_ENV execute immediate 'drop table t1';
&_ENV delete from t;
end;
/
update t set object_id = 0 where rownum <= 10;
commit;
Running that in "PROD" means the two commands are commented out, where in "DEV" they would be run.