关于游标的一点发现

王朝other·作者佚名  2008-05-19
宽屏版  字体: |||超大  

昨天在写存储过程的时候发现了一个以前忽视了的地方,不知道对大家有没有用。

创建显性游标:

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;

/

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有