Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sql*plus: How to avoid prompting for &1 ?

Sven W.Mar 15 2012 — edited Mar 16 2012
I use a parameter inside an SQL Plus Script to set a value for the creation of different environments.
DEFINE _env = '&1'
The parameter &1 is used. However a NULL value is allowed. But if this parameter is not set then sql*plus prompts to enter something for &1. How can we avoid that?

sql plus call
sqlplus user/password@database @test_parameter.sql

SQL> exit

Verbunden mit:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options

"Geben Sie einen Wert f³r 1 ein:"

SQL> prompt Env&_env.
Env
SQL>
I'm looking for an easy way to avoid the message <font color="red">"Enter a value for 1:"</font> if no parameter is added.
If a parameter is added, then this message does not appear.
sqlplus user/password@database @test_parameter.sql _TST
sample script
-- set environment 
------------------
-- Allowed values are 
-- "_DEV" = Development 
-- "_TST" = Test
-- "" = Production)
set verify off

DEFINE _env = '&1'

begin 
  if '&_env' is null 
    or regexp_like ('&_env', '_[[:alnum:]]{3}') then 
     null; --ok
  else
    raise_application_error(-20000,'Parameter 1 (''&_env'') has wrong value. Must start with _ and only 3 letters or be empty.' );
  end if;
end;
/

set echo on

prompt env&_env.
Edited by: Sven W. on Mar 15, 2012 4:40 PM
This post has been answered by AdamMartin on Mar 15 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2012
Added on Mar 15 2012
8 comments
9,413 views