Use:
CREATE OR REPLACE PROCEDURE MY_SPROC() RETURN SYS_REFCURSOR
L_CURSOR SYS_REFCURSOR;
BEGIN
OPEN L_CURSOR FOR
SELECT * from MYTABLE;
RETURN L_CURSOR;
END;
Use this if you want to run dynamic SQL on Oracle:
CREATE OR REPLACE PROCEDURE MY_SPROC() RETURN SYS_REFCURSOR
L_CURSOR SYS_REFCURSOR;
L_QUERY VARCHAR2(5000) DEFAULT 'SELECT ...';
BEGIN
OPEN L_CURSOR FOR L_QUERY;
RETURN L_CURSOR;
END;
If you want to include bind variables in the dynamic SQL:
CREATE OR REPLACE PROCEDURE MY_SPROC() RETURN SYS_REFCURSOR
L_CURSOR SYS_REFCURSOR;
L_QUERY VARCHAR2(5000) DEFAULT 'SELECT ...';
BEGIN
OPEN L_CURSOR FOR L_QUERY
USING bind_var1;
RETURN L_CURSOR;
END;