&1 asks for a user-entered value. Notice how the entered mytable value mytable replaced with &1 below:
SQL> SELECT COUNT(*) FROM &1 WHERE col1 = 12; Enter value for 1: mytable old 1: SELECT COUNT(*) FROM &1 WHERE col1 = 12 new 1: SELECT COUNT(*) FROM mytable WHERE col1 = 12 COUNT(*) ---------- 0
The dot ( . ) Adds each non-spatial character that follows the dot to the entered value. Note how the value of table after the point is added to the input my :
SQL> SELECT COUNT(*) FROM &1.table WHERE COL1 = 12; Enter value for 1: my old 1: SELECT COUNT(*) FROM &1.table WHERE COL1 = 12 new 1: SELECT COUNT(*) FROM mytable WHERE COL1 = 12 COUNT(*) ---------- 0
Two points in &1..xxdt are not a special operator. The first dot means adding; the second point is literal. It looks like &1 in your example is used to query for the schema / owner name. The note below, as I entered ed and &1..mytable , is converted to ed.mytable :
SQL> SELECT COUNT(*) FROM &1..mytable WHERE COL1 = 12; Enter value for 1: ed old 1: SELECT COUNT(*) FROM &1..mytable WHERE COL1 = 12 new 1: SELECT COUNT(*) FROM ed.mytable WHERE COL1 = 12 COUNT(*) ---------- 0
Addendum : David Aldridge's great suggestion is to include a quick explanation of SET DEFINE , which goes hand in hand with variable substitution. Here goes ...
The substitutions above are performed by SQLPlus, and its behavior can be controlled using SET DEFINE :
SET DEFINE ON allows you to replace and use a specific substitution character. This is usually the default SQLPlus value, and this was the case when I ran the queries above.SET DEFINE <char> sets the replacement character. Ampersand ( & ) is the default. SQLPlus will only accept alphabetic characters, not spaces for the replacement character. Please note that I have never had to change this value for more than a decade of using Oracle.SET DEFINE OFF will stop the substitution. Use this if you need to have the actual ampersand in your query or proc, because SQLPlus will treat the ampersand as a replacement character no matter where you put it, including in a string.
source share