---------------------------------------------游标(cursor)应用-实例-----------------------------------------------------------------
declare
type curt_type is ref cursor;--申明ref类型cursor
type nticketinfoid is table of pwr_user.nticketinfoid%type;
type ndealid is table of pwr_user.ndealid%type;--申明table类型数据集
type sbarcode is table of pwr_user.sbarcode%type;
type sselldate is table of pwr_user.sselldate%type;
cur_s curt_type;--申明fef类型cursor
ticket nticketinfoid;--申明变量类型为前面的table数据集类型
nde ndealid;
sback sbarcode;
dates sselldate;
begin
--打开cursor
open cur_s For ‘select nticketinfoid,ndealid,sbarcode,sselldate from pwr_user where nticketinfoid<=:额‘
using ‘212657‘;--为前面参数赋值,注意用单引号引起来 冒号在等号后面,只能在using 后面用分号结尾
fetch cur_s bulk collect into ticket,nde,sback,dates;--全部把数据提取出来保存在申明的table变量里面
close cur_s;--关闭游标
For i in ticket.first..ticket.last loop--循环输出
if ticket(i)=‘212657‘ then--判断如果相等进行替换
ticket(i):= ‘0123456789‘;end if;
if sback(i)=‘140217100000‘ then
sback(i):= ‘我是___‘;end if;
dbms_output.put_line(ticket(i)||‘ ‘||nde(i)||‘ ‘||sback(i)||‘ ‘||dates(i));
end loop;
end;
--cursor{1.隐示cursor,2.显示cursor,3.ref游标,ref游标一般存储过程和包里面使用}
-- desc pwr_user;
--select * from pwr_user;