SQL*Plus: Using substitution variables 

Joined:
04/09/2007
Posts:
753

September 10, 2008 19:52:55    Last update: September 10, 2008 19:52:55
A substitution variable is preceded by one or two ampersands (&). When you run a SQL command with substitution variables, you'll be prompted for the value of each variable.

The one ampersand version prompts for a value and use it for the current query. The two ampersands version uses the value for the current query and remembers it. Just like you did a DEFINE myvar 'The Value', so you won't be prompted again for subsequent queries using the same variable.

To enter a literal ampersand, you need to SET ESC on and use the escape character before the ampersand (&).

You can also use substitution variables with a script, but you follow the ampersand by a number instead of a name. When you call the script with START or @, &1 will be replaced by the first argument, &2 by the second argument, so on...
Share |
| Comment  | Tags