2016-09-23 64 views
0

我在Oracle中創建的過程如下如何在oracle中運行遊標輸出的程序?

create or replace procedure jobsfetch 
(id varchar2,jobcursor out sys_refcursor) 
as 
begin 
open jobcursor for 
    select * from shop.jobs where job_id = id; 
end; 

我在SQL運行程序* Plus中使用:

exec jobsfetch('AD_ASST'); 

但我發現了以下錯誤

ERROR at line 1: 
ORA-06550: line 1, column 7: 
PLS-00306: wrong number or types of arguments in call to 'JOBSFETCH' 
ORA-06550: line 1, column 7: 
PL/SQL: Statement ignored 

如何執行這個程序,因爲它只有一個輸入參數?

+0

嘗試此網址https://oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets –

+1

如果在調用時傳遞給proc的參數數量。你proc需要2個輸入,並在你打電話你只傳遞1,因此你得到錯誤 – XING

回答

0

試試這個:

variable CURSOR_LIST REFCURSOR; 
exec jobsfetch('AD_ASST',:CURSOR_LIST); 
print CURSOR_LIST; 
+0

雖然這段代碼可以解決這個問題,[包括解釋](http://meta.stackexchange.com/questions/114762/解釋完全基於代碼的答案)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 –

0

您可以簡單地用一個PLSQL塊:

declare 
    outCur sys_refcursor; 
begin 
    jobsfetch('AD_ASST', outCur); 
    /* what you need to do with the cursor */ 
end; 
0

的問題是,你的過程有一個輸出參數,但是您不提供它。

您不能exec jobsfetch('AD_ASST'); 我建議把整個東西放在一個像Aleksej這樣的plsql塊中。

declare 
    outCur sys_refcursor; 
begin 
    jobsfetch('AD_ASST', outCur); 
    /* what you need to do with the cursor */ 
end; 

這會給你在outCur中打開的光標,你可以做任何你需要做的事情。

相關問題