SQL> create table aaa(
2 id number primary key not null,
3 name varchar(10) unique not null,
4 sex varchar(2) not null,
5 dept varchar(20) not null);
已经插入3个男生,2个女生,都是计算机专业的
现在创建一 个显式游标使其指向这个结果集,然后利用游标将院系修改为“软件”。
求具体代码.只是在网上看了一些例子,但是用起来都不对
如果是要修改,表aaa字段dept的值,可以在遍历游标的同时执行update更新语句。
create or replace procedure aaa_cursor
is
v_id aaa.id%type;
v_dept aaa.dept%type;
cursor cursor_dept is
select id,dept from aaa; //这里可以设定条件,通过追加where实现
begin
open cursor_dept ;
loop
fetch cursor_dept into v_name,v_sal;
exit when cursor_dept%notfound;
update aaa set dept='软件' where id=v_id;
end loop;
close cursor_dept;
end;