oracle简单的游标使用问题.帮忙看下.。

来源:百度知道 编辑:UC知道 时间:2024/06/05 10:44:04
--以下是使用游标将emp表中的数据删除;
----运行时有一个错误,。大家帮忙找下; 顺便修改一下代码.!谢谢了

declare
--表示emp表中的一条行类型;
rowt emp%rowtype;
--表示emp表中empno列的类型;
eno number;
--声明游标,。并加上行级锁;
cursor c is select * from emp for update;

begin
--输入员工编号;
eno:=&Input_EMPNO;
--打开游标;
open c;
--取得游标中的一行记录;
fetch c into rowt;
--删除当条游标记录;
delete emp where empno=eno current of c;
--关闭游标;
close c;
end;

你的游标定义有问题,你的游标是取全表,但是删除当前行却要根据empno条件,那么当前行不一定是符合条件的记录,你应该这样定义游标:
cursor c is select * from emp where empno=eno for update;
如果你只是想删除符合条件的记录,没必要用游标啊,直接删除不就可以了:
delete from emp where empno=eno ;
commit;

agree with upstair