我有包已经声明了游标。我想将该光标作为PROCEDURE的OUT变量返回。 我不能只从该游标获取数据,因为需要首先通过load_data proc加载数据。 我不想使用那个MMM_CURSOR,因为它有额外的功能,它使用相同的选择 - 写入数据库级别的文件。
create or replace PACKAGE BODY PCG_MMM AS
CURSOR MMM_CURSOR(OFFSET NUMBER) IS
SELECT TYPE, VALUE FROM MMM_TEMP_LOGS WHERE VALUE = OFFSET;
TYPE RET_TYPE IS REF CURSOR;
PROCEDURE LOAD_DATA AS
-- loading data into MMM_TEMP_LOGS--
END LOAD_DATA;
PROCDURE WRITE_TO_FILE AS
BEGIN
-- writing to file here --
END WRITE_TO_FILE;
PROCEDURE GET_DATA(DATA RET_TYPE, OFFSET NUMBER:=0) AS
BEGIN
LOAD_DATA;
DATA := MMM_CURSOR(OFFSET) ; <--- ??
END GET_DATA;
END PCG_MMM;
答案 0 :(得分:2)
您无法将CURSOR传递出过程,但您可以传递引用游标。你也不能只将光标转换为引用光标。
所以如果你想在几个地方使用那个光标+有能力把它传出来,那么我建议你把它改成一个视图,用它来代替光标。
例如
create view MMM_VIEW
as
SELECT TYPE, VALUE FROM MMM_TEMP_LOGS;
(如果您在其中传递变量并需要保持这种性能,请查看“参数化视图”)
create or replace PACKAGE BODY PCG_MMM AS
TYPE RET_TYPE IS REF CURSOR;
PROCEDURE LOAD_DATA AS
-- loading data into MMM_TEMP_LOGS--
for r_cur in (select * from mmm_view) loop...or whatever (replace the cursor with the view)
END LOAD_DATA;
PROCDURE WRITE_TO_FILE AS
BEGIN
-- writing to file here --
END WRITE_TO_FILE;
PROCEDURE GET_DATA(DATA out RET_TYPE, OFFSET NUMBER:=0) AS
BEGIN
LOAD_DATA;
open DATA for select * From mmm_view where value = OFFSET;
END GET_DATA;
END PCG_MMM;