问题
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