?
Solved

oracle script defaulting a variable

Posted on 2012-09-10
1
Medium Priority
?
303 Views
Last Modified: 2012-09-15
How is s SQL script variable tested for not being defined and if not defined  set a default value.

A very simple example to describe the issue.  In the third input example I want the missing &3 to default to *. The real problem is much more complicated, this simply defineds the issue.

@test_script T_user kee *
@test_script T_user kee user_id
@test_script T_user kee

--------------------------------------------
-- test_script.sql
define col_name=&3
select &col_name from &1  where user_id like '%&2%';

----------------------------------------------

what I would like to have happen

if &3 is null then
     define col_name=*
else
   define col_name=&3
end if;

select &col_name from &1  where user_id like '%&2%';
0
Comment
Question by:fpkeegan
1 Comment
 
LVL 35

Accepted Solution

by:
johnsone earned 1000 total points
ID: 38384496
Have a look at the ACCEPT command.  I don't think you can incorporate that into a passed parameter, but it allows a default value:

http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve005.htm#BACGJIHF

Another way could be to use a dummy value, like 'ALL' and then you could do something like this:

col col_name new_value col_name_new
select decode('&3', 'ALL', '*', '&3') col_name_new from dual;

This would set the value of the col_name parameter.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question