It works for one SQL command only.
It is standard ANSI notation.
I'm using it in SQL Developer.
One possible approach, if you just need to specify a parameter once and replicate it in several places, is to do something like this:
SELECTstr_size /* my variable usage */, LPAD(TRUNC(DBMS_RANDOM.VALUE * POWER(10, str_size)), str_size, '0') randFROMdual /* or any other table, or mixed of joined tables */CROSS JOIN (SELECT 8 str_size FROM dual); /* my variable declaration */
This code generates a string of 8 random digits.
Notice that I create a kind of alias named str_size
that holds the constant 8
. It is cross-joined to be used more than once in the query.
Sometimes you need to use a macro variable without asking the user to enter a value. Most often this has to be done with optional script parameters. The following code is fully functional
column 1 noprint new_value 1select '' "1" from dual where 2!=2;select nvl('&&1', 'VAH') "1" from dual;column 1 cleardefine 1
Similar code was somehow found in the rdbms/sql directory.