Oracle游标的定义格式说明
Oracle游标的定义格式说明
游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用fetch语句可以移动该指针,从而对游标中的数据进行各种操作,然后将操作结果写回数据表中。如下例子注释与说明: set serveroutput ondeclare
sh_no tssa.entry_sheet_td.sheet_no%type; --该程序定义sh_no为与tssa.entry_sheet_td数据表中的sheet_no字段类型相同的变量
v_flow_inst tssa.entry_sheet_td.PROCESSINSTID%type;
cursor mycursor is
select sheet_no from entry_sheet_td a ,wfprocessinst b where a.processinstid=b.processinstid and b.currentstate='7';
cursorrecord mycursor%rowtype; --mycursor为从entry_sheet_td数据表中提取的接入型障碍中流程结束而未归档工单数据构成的游标,cursorrecord mycursor%rowtype定义记录变量
begin
sh_no:='';
open mycursor; --打开游标,打开游标的过程有以下两个步骤:1、将符合条件的记录送入内存,2、将指针指向第一条记录。
loop
fetch mycursor into cursorrecord; --要提取游标中的数据,使用fetch命令,语法形式如:fetch 游标名 into 变量名1, 变量名2,……;
exit when mycursor%notfound; --当当前循环的记录值为空时,即循环结束后,退出循环
sh_no:=cursorrecord.sheet_no;
dbms_output.put_line(sh_no); --输出当前满足条件的工单号,此处可以进行一些逻辑处理 end loop;
close mycursor; --关闭游标
end; 上面只是对游标写法的一个简要说明。
评论暂时关闭