Plsql 带有'的程序错误&';

Plsql 带有'的程序错误&';,plsql,procedure,Plsql,Procedure,我正在尝试用蟾蜍执行下面的程序 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_e

我正在尝试用蟾蜍执行下面的程序

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;

我计划在执行变量时将值传递给该变量。

&
是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;

创建或替换程序tst_excp(编号为var_empid)——非常感谢Zohar。它对我有用:-)我不得不评论var_empid(第三行),因为它现在是一个重复条目。
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;