1
我正在嘗試執行接收REFCURSOR並執行一些數據操作的函數。將RefCursor傳遞給函數時無效光標
爲了測試我的功能我有這樣的SQL/PLUS代碼:
var some_cursor REFCURSOR;
exec :some_cursor := SCHEMA.test_getcursor;
print some_cursor;
variable res varchar2;
exec :res := SCHEMA.second_function(:some_cursor, 'Other_parameter');
print res;
現在,第一test_getcursor
函數是一個簡單的函數,打開遊標,執行select查詢並返回光標。它工作得很好,它也打印some_cursor
也很好。
當我調用second_function
並將refcursor傳遞給它時,會發生此問題。
功能具有下面的代碼:
type cursor_row
IS RECORD
(field_1 some_field1%type,
field_2 some_field2%type,
field_3 some_field3%type);
new_row cursor_row;
BEGIN
LOOP
fetch PASSED_IN_REFCURSOR INTO new_row --this is where the function fails
...data manipulation...
EXIT WHEN PASSED_IN_REFCURSOR%NOTFOUND;
END LOOP;
CLOSE PASSED_IN_REFCURSOR;
END;
我得到的錯誤是Invalid Cursor
。
我確定我創建的類型具有與參考遊標相同數量的行和相同的數據類型。
我在這種情況下做錯了什麼?我使用Oracle 10g中,PL/SQL 10.2
使用函數和存儲過程有什麼不同嗎?它看起來像當我使用一個函數並做同樣的事情時,它回來說'錯誤報告:光標已關閉' – Victor 2013-02-27 17:03:55