2011-05-15 47 views
-1

我該如何創建帶有參數的ref curser並從plsql函數返回這個光標? 我試着寫這樣的代碼..用參數創建ref curser?

create or replace function get_ref_cur(id in number) return sys_refcursor is 
ref_curs sys_refcursor; 
begin 
    open ref_curs(std_id number) for select * from student where id = std_id; 
return ref_curs; 
end; 

但是這個代碼不工作。

+0

每個問題一個'?'就足夠了。 「沒有工作」不是一個好問題描述,請說明它做了什麼/不做什麼(無法​​編譯?,返回錯誤數據?,...) – Mat 2011-05-15 08:57:50

+0

什麼是「ID」和「STD_ID」?如果ID是一個表列,則不需要它作爲函數參數的名稱。如果STD_ID是表列,那麼「(std_id號碼)」試圖做什麼? – 2011-05-15 09:55:27

+0

id是一個表列,而std_id是遊標參數問題,在我寫入遊標的參數時打開ref_curs(std_id number)編譯器給出語法錯誤。 – sahar 2011-05-15 10:56:47

回答

1

您不應該需要將參數應用於普通的sys_refcursor。

create or replace function get_ref_cur(id in number) return sys_refcursor is 
ref_curs sys_refcursor; 
begin 
    open ref_curs for select * from student where std_id = id; 
return ref_curs; 
end;