top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Oracle: What is the significance of the &, and && operators in PL SQL?

+2 votes
895 views
Oracle: What is the significance of the &, and && operators in PL SQL?
posted Dec 24, 2014 by Archana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The '&' operator means that the PL SQL block requires user input for a variable. The '&&' operator means that the value of this variable should be the same as inputted by the user previously for this same variable.

answer Dec 29, 2014 by Arun Gowda
0 votes

"&" 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'

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'

"&&" 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'

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

The "&&" will actually define the variable similarly to what the DEFINE command or OLD_VALUE/ NEW_VALUE clauses of a COLUMN statement would have done.
SQL> define
DEFINE NAME = "SCOTT" (CHAR)

answer Dec 29, 2014 by Amit Kumar Pandey
...