# Oracle SQL: Declaring Variable and using in script

**URL:** <https://forums.toadworld.com/t/oracle-sql-declaring-variable-and-using-in-script/56086>\
**Category:** Toad Data Point & Toad Intelligence Central\
**Created:** [September 20, 2022, 8:05pm UTC](https://forums.toadworld.com/t/oracle-sql-declaring-variable-and-using-in-script/56086 "2022-09-20T20:05:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![licsysandops](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@licsysandops](https://forums.toadworld.com/u/licsysandops)\
**Post date:** [September 20, 2022, 8:05pm UTC](https://forums.toadworld.com/t/oracle-sql-declaring-variable-and-using-in-script/56086/1 "2022-09-20T20:05:22Z")

</div>

I'm attempting to declare variables for use in several scripts in the same editor. This is so that multiple updates are needed when using the script for a new user.  
Here's an example of what I'm trying to use:

DECLARE  
Rep\_Name NVARCHAR(250);

BEGIN  
Rep\_Name := 'Kristi Barrickman';

SELECT REP\_CODE, REP\_NAME, REP\_SF\_ID, REP\_TEAM, RESPONSE\_TEAM, REP\_WORKGROUP  
FROM USER\_LIST  
WHERE 1=1  
AND CURRENT\_RECORD=1  
AND REP\_NAME = :Rep\_Name;

END;

---

<div class="post-metadata">

**Author:** ![Gary.Jerep](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gary.jerep/32/205_2.png) [@Gary.Jerep](https://forums.toadworld.com/u/Gary.Jerep)\
**Post date:** [September 20, 2022, 9:12pm UTC](https://forums.toadworld.com/t/oracle-sql-declaring-variable-and-using-in-script/56086/2 "2022-09-20T21:12:38Z")

</div>

Welcome back the Toad for Oracle forum.

Your question is not Toad product related, but rather database/syntax related. Nevertheless, other users may have some insight for you. One thing I have noticed is that different database platforms can treat variables differently. In your case, you're using a bind variable, which might be tripping up your objective to use the variable value in different places. See, link below, which discusses use of &var vs. :var, for example...

> <https://stackoverflow.com/questions/3564283/how-to-declare-variable-and-use-it-in-the-same-oracle-sql-script>

---

<div class="post-metadata">

**Author:** ![Shimonj](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Shimonj](https://forums.toadworld.com/u/Shimonj)\
**Post date:** [September 21, 2022, 7:39am UTC](https://forums.toadworld.com/t/oracle-sql-declaring-variable-and-using-in-script/56086/3 "2022-09-21T07:39:33Z")

</div>

Hi,  
Using Toad Automation, there is a very simple solution.  
You declare a variable ( I would suggest using variable names that are obvious, such as REP\_NAME\_VAR) at the begining of the script and use the following syntax in the next steps.

where rep\_name = #REP\_NAME\_VAR#  
Sincerely,  
Simon

P.S. I use this feature in most of the scripts that I use.

P.S.S. I just discovered that when I envoke an automation script from another automation script, the variable placeholders are replaced by the current value.  
I assume this is a bug, but as we have not renewed our service contract, I cannot open a ticket on this issue. This should not deter you from using this famntastic feature, as I have found a way to overcome this problem.
