动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   数据库 → 阅读文章

 关于游标的一点发现

作者来源: 
阅读 数 307 人次 , 2006-5-11 11:20:00 


昨天在写存储过程的时候发现了一个以前忽视了的地方,不知道对大家有没有用。
创建显性游标:
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;
/

由于使用的游标的不同,我们最终在使用变量的时候还是有一些小区别的。希望大家以后在调代码的时候少走弯路。
  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:关于触发器的问题
· 下一篇:[Learn Oracle From OTN]基于成本的优化器技术内幕
· 远程检测MS SQL Server账号安全性
· PHP V5.0.0 Beta 1下载地址列表
· Sybase数据库技术(28)
· 存储过程编写经验和优化措施
· MySQL数据导入导出方法与工具


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077