很简单的 if 的SQL更新问题
declare
cursor ns is select name,salary from employee;
nam employee.name%type;
sal employee.salary%type;
begin
open ns;
fetch ns into nam,sal;
while ns%found loop
if sal<2000 then
update employee set salary = salary * 1.2 where salary < 2000;
else
if sal<5000 then
update employee set salary = salary * 1.1 where salary<5000 and salary>2000;
else
update employee set salary = salary * 1.05 where salary>5000;
end if;
dbms_output.put_line('after update salary: '||to_char(sal));
fetch ns into nam,sal;
end loop;
close ns;
commit;
end;
报错为 需要 if 的时候出现了 loop
但是我改成下面的样子就可以运行,这是怎么回事,为什么上面会报错?
declare
cursor ns is select name,salary from employee;
nam employee.name%type;
sal employee.salary%type;
begin
open ns;
fetch ns into nam,sal;
while ns%found loop
if sal<2000 then
update employee set salary = salary * 1.2 where salary < 2000;
end if;
dbms_output.put_line('after update salary: '||to_char(sal));
fetch ns into nam,sal;
end loop;
close ns;
commit;
end;
问题点数:30、回复次数:2Top
1 楼bzszp(SongZip)回复于 2005-06-03 14:57:18 得分 30
if ... then
...
elsif ... then
...
end if;Top
2 楼bluecocoqd(小骗骗)回复于 2005-06-03 15:27:14 得分 0
哈哈,你就是笨蛋醒了又睡吧?Top




