2014-12-31 72 views
0

在Oracle存儲過程的光標中需要傳遞動態變量(表名)的幫助。Oracle存儲過程的光標中的動態變量

我的存儲過程:

CREATE OR REPLACE PROCEDURE ABCDEF 
    (TBL_NAME IN VARCHAR) 
IS 

CURSOR CUR IS SELECT * FROM TABLEA 

BEGIN 

FOR rec 
IN CUR 
LOOP 
. 
. 
. 
END 

我需要光標THIS TABLEA由TBL_NAME變量代替。我試圖讓遊標語句成爲可執行語句,但它並沒有幫助我。

建議,請

+1

的可能重複:http://stackoverflow.com/questions/15786953/cursor-for-loop-with-dynamic-sql-statement另請參見:https://開頭asktom .oracle.com/pls/apex/f?p = 100:11:5045785413478 :::: P11_QUESTION_ID:1288401763279 – xQbert

+0

部分相同,但解決方案仍然不適用於上述過程示例 – user3723562

+0

通常:'sql_text varchar2; cur sys_refcursor ;開始 open cur for sql_text; 結束;' – user2672165

回答

1
Made this working using part of the solution above. Thanks for the suggestions. 

CREATE OR REPLACE PROCEDURE ABCDEF 
(
    TBL_NAME IN VARCHAR 
) IS 

TYPE curtype IS REF CURSOR; 
cur curtype; 
column1 number; 
column2 number; 

cursor sql := 'Select * from ' ||tbl_name; 

Begin 
open cur for cursor_sql; 
fetch cur into column1,column2; 

loop 
. 
. 
. 
close cur; 
End 
+0

讚揚採取提示並應用它們的自我努力。 – xQbert