日期:2014-05-17  浏览次数:20857 次

关于&的用法
oracle 11g中pl/sql中调用过程出错
declare 
  v_sal emp.sal%type;
  begin
  select sal into v_sal from emp where ename=&abc;
  dbms_output.put_line(v_sal);
  end;

 当在pl/sql中执行此代码,提示输入abc参数,当键盘输abc为全数字的时侯,没有问题
 当abc输入参数为字母时,提示:就会发生错误,不是提示no data found错误,而是输入无效。
 不知何故??


------解决方案--------------------
Oracle把这里参数连接符&当成是一个自定义变量了。
这样写就可以了
 select sal into v_sal from emp where ename =  chr(38) 
------解决方案--------------------
 'abc';
或者
 select sal into v_sal from emp where ename =  '&' 
------解决方案--------------------
 'abc';
------解决方案--------------------
这个问题好像很简单的样子,你没加单引号  &abc 表示接收数字的   加上单引号  ‘&abc’  表示字符!  你试试!
------解决方案--------------------

declare 
   v_sal emp.sal%type;
   begin
   select sal into v_sal from emp where ename='&abc';
   dbms_output.put_line(v_sal);
   end;

验证了加上单引号是正确的!