您现在的位置: 万盛学电脑网 >> 程序编程 >> 数据库 >> oracle教程 >> 正文

Oracle 10g Release2新功能之Ref Cursor

作者:佚名    责任编辑:admin    更新时间:2022-06-22

Ref Cursor就是我们定义在服务器端的结果集的reference。 当我们打开一个Ref Cursor的时候,没有任何的数据返回到客户端,相反,数据在服务器上的地址将会被返回到客户端。这样用户就可以自己决定什么时间和以那种方式通过Ref Cursor去取数据。

在以前版本的ODP.NET中,我们可以通过Ref Cursor取数据,但是我们不能把Ref Cursor作为一个Input参数传递给PL/SQL的存储过程和存储函数。但是在Oracle Database 10g Release2,我们能够很简单的把Ref Cursor作为Input参数传递给PL/SQL的存储过程和存储函数。这是Oracle Database 10g Release2的新功能。

我们接下来就以例程的方式来向你介绍这个新功能。

准备数据库

我们要在数据库中生成一个表和一个包,我们接下来的例子会用到。

请用HR用户登录数据库,然后运行下面的脚本。
create table processing_result
(
 status varchar2(64)
);
create or replace package cursor_in_out as
type emp_cur_type is ref cursor return employees%rowtype;
procedure process_cursor(p_cursor in emp_cur_type);
end;
/
create or replace package body cursor_in_out as
procedure process_cursor(p_cursor in emp_cur_type) is
employee employees%rowtype;
begin
 loop
  fetch p_cursor into employee;
  exit when p_cursor%notfound;
  insert into processing_result
  values('Processed employee #' ||
  employee.employee_id || ': ' ||
  employee.first_name || ' ' ||
  employee.last_name);
 end loop;
end;
end;
/

  • 共2页:
  • 上一页
  • 1
  • 2
  • 下一页