Dynamic Variable in Cursor in Oracle stored procedure

跟風遠走 提交于 2021-01-29 08:02:44

问题


Need help in passing dynamic variable (table name) in cursor in Oracle stored procedure.

My stored procedure:

CREATE OR REPLACE PROCEDURE ABCDEF
    (TBL_NAME IN VARCHAR)
IS 

CURSOR CUR IS SELECT * FROM TABLEA 

BEGIN

FOR rec
IN CUR
LOOP
.
.
.
END

I NEED THIS TABLEA in cursor to be replaced by TBL_NAME variable. I tried to make the cursor statement as executable statement but it didn't help me.

Suggestions, please


回答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


来源:https://stackoverflow.com/questions/27722277/dynamic-variable-in-cursor-in-oracle-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!