In SQL * Plus (and various other tools that support SQL * Plus syntax), by default, the tool scans SQL statements looking for substitution variables. This allows you to create SQL * Plus scripts that use the variables defined in SQL * Plus for various reporting tasks.
Since substitution variables begin with an ampersand ('&'), but do not have to be declared in advance, this creates problems if you try to run an SQL statement that includes an ampersand. For example, if you have an INSERT that has a string literal that includes an ampersand, you do not want SQL * Plus to pre-process the statement. Or if I want to select the string "foo and bar"
SQL> set scan off; SQL> ed Wrote file afiedt.buf 1* select 'foo & bar' from dual SQL> / 'FOO&BAR' --------- foo & bar
If I allow SQL * Plus to pre-process the statement, however, the text '& bar' is interpreted as a replacement variable, and I am prompted to enter the text to replace at run time
SQL> set scan on SQL> / Enter value for bar: some value old 1: select 'foo & bar' from dual new 1: select 'foo some value' from dual 'FOOSOMEVALUE' -------------- foo some value
source share