游标的作用
要定位一条记录除了rownum 之外好像只有游标了。游标就是一个迭代器,拥有记录的引用。
通过游标修改数据表
declare
cursor cursor_test is
select * from s_city c where c.provinceid = '23' for update of des;
begin
for cur_rec in cursor_test loop
update s_city set des = des || '游标' where current of cursor_test; -- current of cursor_test 记录的引用
end loop;
end;
cursor cursor_test is
select * from s_city c where c.provinceid = '23' for update of des;
begin
for cur_rec in cursor_test loop
update s_city set des = des || '游标' where current of cursor_test; -- current of cursor_test 记录的引用
end loop;
end;
在游标中使用行类型变量
declare
cursor cursor_test is
select * from s_city c where c.provinceid = '23';
v cursor_test%rowtype;-- v 行类型变量
begin
open cursor_test;
begin
loop
<<curtestloop>>
fetch cursor_test
into v;
dbms_output.put_line(v.cityname);
exit when(cursor_test % Notfound);
end loop;
end;
close cursor_test;
end;
cursor cursor_test is
select * from s_city c where c.provinceid = '23';
v cursor_test%rowtype;-- v 行类型变量
begin
open cursor_test;
begin
loop
<<curtestloop>>
fetch cursor_test
into v;
dbms_output.put_line(v.cityname);
exit when(cursor_test % Notfound);
end loop;
end;
close cursor_test;
end;