2017-03-07 66 views
-2

error screenshot我想在蟾蜍中执行下面的程序。程序错误'&'

create or replace procedure tst_excp as 
    var_sal number; 
    var_empid number; 
    var_excp exception; 
begin 
    select sal into var_sal from emp 
    where empno = &var_empid; 

    if var_sal < 4500 then 
     raise var_excp; 
    end if; 
exception 
    when var_excp then 
     dbms_output.put_line ('The salary is low'); 
end; 

,我在线路收到错误:where empno = &var_empid;

错误信息是:

PL/SQL: ORA-00936: missing expression 

我打算在执行它的值传递给该变量。

回答

1

&是sqlplus(和TOAD,SQL Developer和PL/SQL Developer)运行时变量的一部分。它会提示你执行(在你编译过程的情况下)输入代码中的替换。

如果希望得到该程序的输入,所以它会被添加到在每次运行where子句中,你需要接受它作为一个输入变量:

create or replace procedure tst_excp (var_empid in number) as -- << changed here 
var_sal number; 
var_empid number; 
var_excp exception; 
begin 
    select sal into var_sal from emp 
    where empno = var_empid; -- << changed here too 

     if var_sal < 4500 then 
     raise var_excp; 
    end if; 
    exception 
    when var_excp then 
    dbms_output.put_line ('The salary is low'); 
end; 
+0

非常感谢您琐。它为我工作:-)我不得不评论var_empid(第3行),因为它现在是一个重复的条目。 – aks