I want to create a function that takes some code as an input (e.g. Select * FROM SOME_TABLE
) and returns the result of a query as an output.
I want to use it in procedures in order to return tables as a result.
It should look like this:
BEGIN
--some procedure code
CREATE TABLE SOME_TABLE as Select * FROM ...;
Select * FROM table(my_function('Select * FROM SOME_TABLE'));
END;
Important tips:
where
, having
, partition
, and other Oracle constructions.DBMS_OUTPUT
.I tried to search in the net but could not find a solution that meets all my expectations. The best link I've found was this:
DBMS_SQL.RETURN_RESULT
works if your "code" is a select query
DECLARE
l_cur SYS_REFCURSOR;
l_query VARCHAR2(4000) := 'select * from SOME_TABLE';
BEGIN
OPEN l_cur for l_query;
DBMS_SQL.RETURN_RESULT(l_cur);
END;
/