I need to return a resultset from function and work with this resultset just like with an ordinary table.
So I need something like following:
select * from table(querydb('select * from dual'))
The querydb function should return a resultset of a query passed to it.
Can it be implemented in oracle?
Would be grateful for any information.
If you need a result set and a ref cursor won’t do with a datatype called sys.anydataset. i.e what you seem to want is a pipelined function, but of course with a regular pipelined function you need to define the output structure, which in your case isn’t static.
Enter anydataset. this type allows us to dynamically generate types on the fly (at hard parse time only) to allow us to define pipelined functions with varying outputs.
The coding is a bit complex unfortunately.
To start with, we define a type that will do the processing of the passed in SQL statement.
Next up, we create a package spec that will be basically your
querydbfunction call:the types there will just hold some info about the SQL structure itself (we will be using
DBMS_SQLto describe the input SQL as it has functions to get the number of columns, data types etc out of any given SQL statement.The main type body is where the processing occurs:
once this is done, you can query like: