码迷,mamicode.com
首页 > 数据库 > 详细

oracle-游标(cursor)应用-实例

时间:2015-04-05 17:25:04      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

---------------------------------------------游标(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;

oracle-游标(cursor)应用-实例

标签:

原文地址:http://www.cnblogs.com/aaaaq/p/4394263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!