Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1158514
  • 博文数量: 178
  • 博客积分: 2776
  • 博客等级: 少校
  • 技术积分: 2809
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-22 15:36
文章分类

全部博文(178)

文章存档

2014年(3)

2013年(66)

2012年(109)

分类: Oracle

2012-04-19 11:39:03


除非Statement close物理关闭,否则在这个session在v$open_cursor中相关联的记录将一直存在,不会释放。
jakarta dbcp数据库连接池有一个StatementCache功能,它不会物理关闭Statement,会造成cursor溢出
看来Oracle的Statement不能再客户端进行Cache,当我的cache size就算为1,运行一段时间cursor也会溢出
我们必须Close Statementsession来确保相应Session中打开的游标关闭。
游标(cursor)
声明游标语法:cursor <游标名> is select语句;
声明ref游标语法:<游标名> is ref cursor;
打开游标语法:open <游标名>;
移动游标并获取数据语法:fetch <游标名> into <用于保存读取的数据的变量的名>;
关闭游标语法:close <游标名>;
游标属性(游标的属性必须在关闭游标之前):
%isopen: 判断游标是否打开
%notfound: 找不到数据时
%found:
%rowcount: 返回当前游标已扫描的数据行数量
游标分类:1、显示游标(自定义游标);2、隐示游标(系统游标);3、REF游标
例:
declare
v_row t_test%rowtype; -- 匹配t_test表中一行所有的数据类型
cursor v_cur is select * from t_test;-- 声明游标
begin
open v_cur;-- 打开游标
loop
fetch v_cur into v_row;-- 将游标所在行的数据转存到v_row中
exit when v_cur%notfound; -- 当游标到最后一行时跳出
dbms_output.put_line('id = '||v_row.t_id||' name = '||v_row.t_name||' msg = '||v_row.t_msg);
end loop;
close v_cur;-- 关闭游标
exception
when others then dbms_output.put_line('throw exception: others');
end;
/
-- REF游标 --
create or replace package upk_select_test
as type uc_test is ref cursor; -- 声明ref游标
end upk_select_test;
/
-- Oracle存储过程中调用ref游标,并将查询结果以游标的方式返回
create or replace procedure up_select_test_2
(uc_result out upk_select_test.uc_test)
is
begin
open uc_result for select * from t_test;
end up_select_test_2;
/
关于部分PL/SQL游标基本语法就先介绍到这里,以后会陆续更新技术文章,敬请期待。
阅读(3035) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

娃哈哈8752012-04-23 21:15:57

PL/SQL不能回车 退格 ,如果需要怎么实现???