ITPub博客

首页 > 数据库 > Oracle > 关于游标的一点发现

关于游标的一点发现

原创 Oracle 作者:rainytag 时间:2007-06-21 19:57:30 0 删除 编辑
创建显性游标:
create or replace procedure test
is
cursor test1 is select name from devp;
test2 devp.name%type;
begin
open test1;
loop
fetch test1 into test2;
dbms_output.put_line(test2); --注意,此处用的是test2变量
exit when test1%notfound;
end loop;
close test1;
end;
/

create or replace procedure test
is
cursor test1 is select name from devp;
test2 test1%rowtype;
begin
open test1;
loop
fetch test1 into test2;
dbms_output.put_line(test2.name); --注意,此处用的是test2.name
exit when test1%notfound;
end loop;
close test1;
end;
/


下面用隐性游标试一下:
create or replace procedure test
is
cursor test1 is select name from devp;
test2 devp.name%type;
begin
for test2 in test1 loop
dbms_output.put_line(test2.name); --注意,此处用的是test2.name
end loop;
end;
/

create or replace procedure test
is
cursor test1 is select name from devp;
test2 test1%rowtype;
begin
for test2 in test1 loop
dbms_output.put_line(test2.name); --注意,此处用的是test2.name
end loop;
end;
/

由于使用的游标的不同,我们最终在使用变量的时候还是有一些小区别的。希望大家以后在调代码的时候少走弯路。
[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9650775/viewspace-920303/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 整理的OCI文档
请登录后发表评论 登录
全部评论

注册时间:2008-01-01

  • 博文量
    652
  • 访问量
    2207517