Oracle PLSQL - Declare a cursor on a non-existing table Oracle PLSQL - Declare a cursor on a non-existing table oracle oracle

Oracle PLSQL - Declare a cursor on a non-existing table


You should be able to define your cursor like this:

DECLARE  c SYS_REFCURSOR;BEGIN  OPEN c FOR 'SELECT * FROM dual';  CLOSE c;END;

You can also bind arguments:

OPEN c FOR 'SELECT * FROM dual WHERE DUMMY = :1' USING 'X';

For further information see the Oracle documentation of the OPEN-FOR Statement.

Example using a stored procedure

CREATE OR REPLACE PROCEDURE test IS  c SYS_REFCURSOR;BEGIN  OPEN c FOR 'SELECT * FROM fdfdfdfdfd';  CLOSE c;END;/


Creating temporary tables as required is usually not considered good practice in Oracle, where Global Temporary Tables are better and would not cause this problem


You can use DBMS_SQL to get even more flexibility than the ref cursor method described by Peter Lang. But it means more work, too.