How to pipeline a function with a dynamic number of columns?
122922May 8 2006 — edited Feb 26 2013Hi everyone,
I'm trying to figure out how to write a piplined function that generates a dynamic SQL statement from its inputs, executes the query, and returns the results of the query in the pipeline. The number and names of the columns in the dynamic query is unknown number until the function is invoked.
I suspect that DBMS_SQL is involved, but can't quite figure out how to construct a row using it that I can use PIPE ROW on. I also can't figure out what data type the function should return (ANYDATASET?)
pseudo-PLSQL follows:
create function myfunction ( param1 varchar2)
return anydataset pipelined
as
query_string := <... do stuff with param1 ...>
< -- >
open a cursor for query_string
determine the number of columns
read a row
PIPE ROW it
<--->
Can what I'm trying to do be done?
Thanks,
Keith