2012-12-12 78 views
0

我在我所聲明的遊標包。我想返回光標AS過程的OUT變量。 我不能只是從那個光標導致數據的數據需要由load_data PROC第一次加載。 我wan't使用該MMM_CURSOR原因有附加功能,它使用相同的選擇 - 在DB級別寫入文件。PL/SQL遊標獲取到光標

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; 

回答

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;