Oracle pl/sql引用(返回?)游标/声明游标
有没有办法做到这一点?是否将游标获取的数据输出到refcursor中,而不首先将其填充到表中Oracle pl/sql引用(返回?)游标/声明游标,sql,oracle,cursor,Sql,Oracle,Cursor,有没有办法做到这一点?是否将游标获取的数据输出到refcursor中,而不首先将其填充到表中 create or replace procedure someprocedure ( rc1 in out adv_refcur_pkg.rc) -- this is defined below as v_class_year varchar(10); cursor c1 is select distinct e.pref_class_year from entity e where e.pre
create or replace procedure someprocedure
(
rc1 in out adv_refcur_pkg.rc) -- this is defined below
as
v_class_year varchar(10);
cursor c1
is
select distinct e.pref_class_year
from entity e
where e.pref_class_year between i_start_class and i_end_class;
begin
open c1;
loop
fetch c1 into v_class_year;
EXIT WHEN c1%NOTFOUND;
end loop;
close c1;
open rc1 for select v_class_year from dual;
end;
这是refcursor的声明
CREATE OR REPLACE PACKAGE ADVANCE.adv_refcur_pkg
AS
TYPE RC IS REF CURSOR;
END adv_refcur_pkg;
根据这个例子,是的,有可能:
根据这个例子,是的,有可能:
当您可以简单地传递光标本身时,为什么还要费心这么做呢
create or replace procedure someprocedure
(
rc1 in out adv_refcur_pkg.rc) -- this is defined below
as
begin
open rc1 for
select distinct e.pref_class_year
from entity e
where e.pref_class_year between i_start_class and i_end_class;
end;
当您调用“someprocedure”时,您有一个打开的光标,可以从以下位置获取:
BEGIN
...
someprocedure(TheCursor);
LOOP
fetch TheCursor into v_class_year;
exit when TheCursor%NOTFOUND;
...
END LOOP;
CLOSE TheCursor;
...
END;
当您可以简单地传递光标本身时,为什么还要麻烦地这样做呢
create or replace procedure someprocedure
(
rc1 in out adv_refcur_pkg.rc) -- this is defined below
as
begin
open rc1 for
select distinct e.pref_class_year
from entity e
where e.pref_class_year between i_start_class and i_end_class;
end;
当您调用“someprocedure”时,您有一个打开的光标,可以从以下位置获取:
BEGIN
...
someprocedure(TheCursor);
LOOP
fetch TheCursor into v_class_year;
exit when TheCursor%NOTFOUND;
...
END LOOP;
CLOSE TheCursor;
...
END;
只需打开
rc1
光标以进行c1
光标定义中使用的查询。只需打开rc1
光标以进行c1
光标定义中使用的查询。