Return a fully dynamic table from an Oracle function
It is possible, though quite complicated, to write a pipelined table function that returns a variable structure.  Your pipeline table function could take the two arguments and use the Oracle Data Cartridge interface and the magic of the AnyDataSet type to return a dynamic structure at runtime.  You can then use that in subsequent SQL statements as if it was a table, i.e.

SELECT *
  FROM TABLE( your_pipelined_function( p_1, p_2 ));


A couple more references that discuss the same sample implementation 


Dynamic SQL Pivoting 
The Implementing the Interface Approach section of the Oracle Data Cartridge Developer's Guide