I am trying to write a stored procedure in oracle which takes an IN param and uses this as part of the SELECT query. I want to return a results set exactly the same as if I had simply ran SELECT * FROM table where id = 1; However I cannot seem to find any way to do this?
I have looked at sys_refcursor, dbms_sql.return_result and a few others but these either only compile or compile and return output to a console and not as a query result set.
A simple example of a procedure below
CREATE OR REPLACE PROCEDURE myProc
(
v_id IN table.id%TYPE;
)
AS
BEGIN
--desired query
SELECT * FROM table WHERE id = v_id;
--sys_refcursor which only prints to console
open c1 for
select * from table where id=v_id;
dbms_sql.return_result(c1);
--execute immediate does not return any results set
execute immediate 'SELECT * FROM table WHERE id = v_id';
END;
Are there any other suggestions or ideas on how to achieve this? NOTE: I do not wish to process the results which is why I am not using an INTO clause, even if I did use one it does not return a results set.