Unix Technical Forum

Macro Substitution Variables in Oracle SQL

This is a discussion on Macro Substitution Variables in Oracle SQL within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi - I use Toad as my SQL interface. I have loads of reports which run each month or ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 11:13 AM
Andreww
 
Posts: n/a
Default Macro Substitution Variables in Oracle SQL

Hi - I use Toad as my SQL interface.

I have loads of reports which run each month or where paramaters
(campaign codes, store names etc) change with each report.

As the SQL might be long and complex and the parameters to change could
appear all over the SQL, I was hoping there was some way I could
specify all the variable at the top of the script for the SQL to "pick
up". Thence I don't have to work through the code and chenge the
params.

Anyone got any ideas?

Thanks

Andrew

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 11:13 AM
Sybrand Bakker
 
Posts: n/a
Default Re: Macro Substitution Variables in Oracle SQL

On 25 Aug 2006 04:47:57 -0700, "Andreww" <andrew.whittam@gmail.com>
wrote:

>Hi - I use Toad as my SQL interface.
>
>I have loads of reports which run each month or where paramaters
>(campaign codes, store names etc) change with each report.
>
>As the SQL might be long and complex and the parameters to change could
>appear all over the SQL, I was hoping there was some way I could
>specify all the variable at the top of the script for the SQL to "pick
>up". Thence I don't have to work through the code and chenge the
>params.
>
>Anyone got any ideas?
>
>Thanks
>
>Andrew


In sql*plus you can
define param_1 = '&1'
define param_2 = '&2'
where &1 &2 etc (to a max of 9) are commandline parameters.

Better you would
variable param_1 <datatype>
variable param_2 <datatype>
begin
aram_1 := '&1';
aram_2 := '&2';
end;
/
so you are using proper bind variables.

Toad should support both methods.

--
Sybrand Bakker, Senior Oracle DBA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 11:13 AM
Andreww
 
Posts: n/a
Default Re: Macro Substitution Variables in Oracle SQL

Hi Sybrand - I am a bit confused...

if I had the following code:

select count(*)
from tblCustomers
where store_code='X189';

How would I implement the solution?

Thanks for your help.

Andrew


Sybrand Bakker wrote:
> On 25 Aug 2006 04:47:57 -0700, "Andreww" <andrew.whittam@gmail.com>
> wrote:
>
> >Hi - I use Toad as my SQL interface.
> >
> >I have loads of reports which run each month or where paramaters
> >(campaign codes, store names etc) change with each report.
> >
> >As the SQL might be long and complex and the parameters to change could
> >appear all over the SQL, I was hoping there was some way I could
> >specify all the variable at the top of the script for the SQL to "pick
> >up". Thence I don't have to work through the code and chenge the
> >params.
> >
> >Anyone got any ideas?
> >
> >Thanks
> >
> >Andrew

>
> In sql*plus you can
> define param_1 = '&1'
> define param_2 = '&2'
> where &1 &2 etc (to a max of 9) are commandline parameters.
>
> Better you would
> variable param_1 <datatype>
> variable param_2 <datatype>
> begin
> aram_1 := '&1';
> aram_2 := '&2';
> end;
> /
> so you are using proper bind variables.
>
> Toad should support both methods.
>
> --
> Sybrand Bakker, Senior Oracle DBA


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 11:14 AM
Sybrand Bakker
 
Posts: n/a
Default Re: Macro Substitution Variables in Oracle SQL

On 25 Aug 2006 08:03:14 -0700, "Andreww" <andrew.whittam@gmail.com>
wrote:

>Hi Sybrand - I am a bit confused...
>
>if I had the following code:
>
>select count(*)
>from tblCustomers
>where store_code='X189';
>
>How would I implement the solution?
>
>Thanks for your help.
>
>Andrew



define p_store_code = '&1'
select count(*)
from tblCustomers
where store_code = '&p_store_code'

or

variable p_store_code varchar2(4);
begin
_store_code := '&1';
end;
/
select count(*)
from tblcustomers
where store_code = _store_code

in both cases you would call the script with
<script name> <space> 'X189'

If you don't provide the parameter you will be prompted.

Could you please refrain from top posting?

--
Sybrand Bakker, Senior Oracle DBA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com