error screenshot我正在尝试在Toad中执行以下程序。
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
我打算在执行时将值传递给变量。
答案 0 :(得分: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;