----隐式游标
begin
for c_row in ( select open_time, group_id, sm_code, cn
from dchncustmsg
where open_time = '20041109'
and sm_code = '3g';)
loop
dbms_output.put_line(c_row.open_time||'-'||c_row.group_id||'-'||c_row.sm_code||'-'||c_row.cn);
end loop;
end;
--------------------------------------------------------
----For 循环游标
declare
--类型定义
cursor c_cur
is
select open_time, group_id, sm_code, cn
from dchncustmsg
where open_time = '20041109';
--定义一个游标变量c_row c_cur%rowtype,该类型为游标c_cur中的一行数据类型
c_row c_cur%rowtype;
begin
for c_row in c_cur loop
exit when c_cur%notfound;
dbms_output.put_line(c_row.open_time||'-'||c_row.group_id||'-'||c_row.sm_code||'-'||c_row.cn);
end loop;
end;
--------------------------------------------------------
----Fetch 循环游标
----使用是必须明确打开和关闭
declare
--类型定义
cursor c_cur
is
select open_time, group_id, sm_code, cn
from dchncustmsg
where open_time = '20041109'
and sm_code = '3g';
--定义一个游标变量c_row c_cur%rowtype,该类型为游标c_cur中的一行数据类型
c_row c_cur%rowtype;
begin
open c_cur;
loop
--提取一行数据到c_row
fetch c_cur into c_row;
--判断是否取到值,未取到则退出
--取到值 c_cur%notfound 是 false
--未取到值c_cur%notfound 是 true
exit when c_cur%notfound;
dbms_output.put_line(c_row.open_time||'-'||c_row.group_id||'-'||c_row.sm_code||'-'||c_row.cn);
end loop;
close c_cur;
end;
阅读(1821) | 评论(6) | 转发(0) |