CREATE OR REPLACE
procedure mytest
(
--动态游标
p_result out NC.N_CURSOR
)
is
p bd_invcl_temp%rowtype;
begin
open p_result for
select * from bd_invcl_temp;--处理结果集内容
loop
fetch p_result into p;
exit when p_result%notfound;
if (p.invcl_code='A01000') then
p.invcl_code:='';
end if;
end loop;end mytest;请问一下:我已经循环过一次游标,游标已经指向最后一行了,如果重新回到open时的位置???
procedure mytest
(
--动态游标
p_result out NC.N_CURSOR
)
is
p bd_invcl_temp%rowtype;
begin
open p_result for
select * from bd_invcl_temp;--处理结果集内容
loop
fetch p_result into p;
exit when p_result%notfound;
if (p.invcl_code='A01000') then
p.invcl_code:='';
end if;
end loop;end mytest;请问一下:我已经循环过一次游标,游标已经指向最后一行了,如果重新回到open时的位置???
[说明]
在使用FETCH语句之前必须先打开游标,这样才能保证工作区中有数据.
对游标第一次使用FETCH语句时,游标指针指向第一条记录,因此操作的对象是第一条记录,使用后,游标指针指向下一条记录.
游标指针只能向下移动,不能回退.如果想查完第二条记录后又回到第一条记录,则必须关闭游标,然后重新打开游标.
INTO子句中的变量个数,顺序,数据类型必须与工作区中每行记录的字段数,顺序以及数据类型一一对应.
2、CREATE OR REPLACE
procedure mytest
(
--动态游标
p_result out NC.N_CURSOR
)
is
type table_type is table of bd_invcl_temp%rowtype;
p table_type;
--p bd_invcl_temp%rowtype; -- 这个就不要了。
begin
open p_result for
select * from bd_invcl_temp; --处理结果集内容
fetch p_result bulk collect into p;
for i in p.first..p.count loop
if (p(i).invcl_code='A01000') then
p(i).invcl_code:='';
end if;
end loop;
end mytest;
p(1)就是起始位置。for i in p.first..p.count loop
if (p(i).invcl_code='A01000') then
p(i).invcl_code:='';
end if;
end loop;
但是楼主注意,第二次打开的游标里面的数据不一定跟第一次的一样。如果这个时候有其他连接对表进行了insert、update、delete并commit了,那么第二次打开的游标将会是更改后的结果集。为什么不在一个循环里面处理呢?