Oracle存储过程中游标中的动态变量

时间:2014-12-31 14:10:48

标签: oracle stored-procedures cursor

需要帮助在Oracle存储过程中的游标中传递动态变量(表名)。

我的存储过程:

CREATE OR REPLACE PROCEDURE ABCDEF
    (TBL_NAME IN VARCHAR)
IS 

CURSOR CUR IS SELECT * FROM TABLEA 

BEGIN

FOR rec
IN CUR
LOOP
.
.
.
END

我需要光标中的这个TABLEA被TBL_NAME变量替换。我试图将游标语句作为可执行语句,但它并没有帮助我。

建议,请

1 个答案:

答案 0 :(得分: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