在这个小小的声明中,任何人都能帮助我解决我的错误吗?
declare
cursor emp_cursor is
select employee_id, quantity * salary AS price
from employees;
emp_row emp_cursor%rowtype;
begin
open emp_cursor;
if (price < 2,000)
then price := 2,000 * 0.15;
else if (price >= 2,000)
then price := 2,000 * 0.20;
loop
fetch emp_cursor into emp_row;
exit when emp_cursor%notfound;
dbms_output.put_line(emp_row.employee_id || ' ' || emp_row.price);
end loop;
close emp_cursor;
end;
我正在使用pl / sql开发人员。
答案 0 :(得分:1)
在你的比较中摆脱',':
if (price < 2,000)
是语法错误。如果你的意思是2E0,只需写2,如果你的意思是2E3,写2000。
答案 1 :(得分:1)
答案 2 :(得分:0)
您的价格应为emp_row.price。然后把你的if退出...你必须先打开,先获取光标。然后处理行并关闭光标。当您使用变量而不是emp_row.price时,代码更清晰。例如,如果emp_row.price&lt; 2000 - 然后v_price:= 2000 * 0.15 ......并删除你的数字中的逗号。
loop
fetch emp_cursor into emp_row;
exit when emp_cursor%notfound;
if (emp_row.price < 2000) then....
....
end if;
dbms_output.put_line(emp_row.employee_id || ' ' || emp_row.price);
end loop;
....