declare
  v_sal emp.sal%type;
begin
  select sal into v_sal from emp where empno=&&no;
 case
   when v_sal<30 then
      update emp set sal=44 where empno=&no;
  end case;
end;
两个&&和&有什么不同之处,它们的作用是什么?请各位高手不吝赐教,谢谢了

解决方案 »

  1.   

    在同一会话中&&表示对变量只赋值一次,以后SQL都用该值运行。
    比如在一个会话中:
    select sal into v_sal from emp where empno=&&no; 
    你赋值后,不论运行多次该SQL,都以你这一次给的值运行。而&则是运行一次就需你赋值一次。
      

  2.   

        &用来创建一个临时变量,每当遇到这个临时变量时,都会提示你输入一个值。  &&用来创建一个持久变量,就像用用define命令或带new_vlaue字句的column命令创建的持久变量一样。当用&&命令引用这个变量时,不会每次遇到该变量就提示用户键入值,而只是在第一次遇到时提示一次。
      如,将下面三行语句存为一个脚本文件,运行该脚本文件,会提示三次,让输入deptnoval的值:  select count(*) from emp where deptno = &deptnoval;
      select count(*) from emp where deptno = &deptnoval;
      select count(*) from emp where deptno = &deptnoval;  将下面三行语句存为一个脚本文件,运行该脚本文件,则只会提示一次,让输入deptnoval的值:    select count(*) from emp where deptno = &deptnoval;
      select count(*) from emp where deptno = &deptnoval;
      select count(*) from emp where deptno = &deptnoval;