Toad World® Forums

Using Variables


#1

Hi–

I am trying to define a variable and then use it in a query. As I am defining it in the code, I don’t want to be prompted with the “Bind Variables” box. I must be doing something wrong because the variable is not getting defined and I always get prompted with the “Bind Variables” box:

VARIABLE VAR1 NUMBER;
EXEC :VAR1 := 1;
SELECT *
FROM “TRANSACTION” tt
WHERE tt.bllng_id = :var1;

Thanks for the help!!


#2

I’m not completely certain what database type you are using. If you are using Oracle use an anonymous block by using BEGIN and END. If Sql Server use the @ symbol instead of colon.

Debbie


#3

Thanks Debbie. I am using Oracle. Could you provide a sample of the anonymous block? I have tried to do this via snippets taken from the web but can not get it working. Thank you!


#4

DECLARE

VAR1 CHAR := ‘X’;

VAR2 CHAR;

SELECT ‘1’ INTO VAR2

WHERE dummy = VAR1;

END;

You don’t really want to bind the variable but just define and use the variable. Simpel example below.

BEGIN FROM dual tt