Monday, May 16, 2005

ORACLE: What is the difference between & and &&?

Culled from here.

What is the difference between & and && in a SQL script:

"&" is used to create a temporary substitution variable that will prompt you for a value every time it is referenced. Example:

SQL> SELECT sal FROM emp WHERE ename LIKE '&NAME';
Enter value for name: SCOTT
old 1: SELECT sal FROM emp WHERE ename LIKE '&NAME'
new 1: SELECT sal FROM emp WHERE ename LIKE 'SCOTT'

SAL
----------
3000

SQL> /
Enter value for name: SCOTT
old 1: SELECT sal FROM emp WHERE ename LIKE '&NAME'
new 1: SELECT sal FROM emp WHERE ename LIKE 'SCOTT'

SAL
----------
3000
"&&" is used to create a permanent substitution variable. Once you have entered a value (defined the variable) its value will used every time the variable is referenced. Example:

SQL> SELECT sal FROM emp WHERE ename LIKE '&&NAME';
Enter value for name: SCOTT
old 1: SELECT sal FROM emp WHERE ename LIKE '&&NAME'
new 1: SELECT sal FROM emp WHERE ename LIKE 'SCOTT'

SAL
----------
3000

SQL> /
old 1: SELECT sal FROM emp WHERE ename LIKE '&&NAME'
new 1: SELECT sal FROM emp WHERE ename LIKE 'SCOTT'

SAL
----------
3000

[Listening to: Will Smith - Will 2K]

Fixed typo in subject

No comments: