I am using dynamic SQL to generate a recordset. It is dynamic because it is part of a metadata driven solution and the columns returned by the query are not known at compile time, and need to be capable of being changed without recompilation.
This cursor is used to update/append another which has a known, fixed structure, this second cursor will be returned to an external ETL tool to perform the actual update of a table in another database. There will always be more columns in the second cursor than the first.
So, the requirement is to generate a cursor of the second fixed, format, with the columns in common with the first populated and the rest null. The second cursor is then returned from the package using a PIPELINE function.
I can generate the list of columns so I thought of building some dynamic SQL like
INSERT INTO cur_second (Field1, Field2, Field3 ....) SELECT <SQL for first cursor>
however EXECUTE IMMEDIATE does not like cursor names, it seems to need a table, and the table will not exist in the current database.
I'm sure there's a solution out there using ref cursors, or temp tables or summat, but so far the most elegant route escapes me. Any PL/SQL gurus out there?
This cursor is used to update/append another which has a known, fixed structure, this second cursor will be returned to an external ETL tool to perform the actual update of a table in another database. There will always be more columns in the second cursor than the first.
So, the requirement is to generate a cursor of the second fixed, format, with the columns in common with the first populated and the rest null. The second cursor is then returned from the package using a PIPELINE function.
I can generate the list of columns so I thought of building some dynamic SQL like
INSERT INTO cur_second (Field1, Field2, Field3 ....) SELECT <SQL for first cursor>
however EXECUTE IMMEDIATE does not like cursor names, it seems to need a table, and the table will not exist in the current database.
I'm sure there's a solution out there using ref cursors, or temp tables or summat, but so far the most elegant route escapes me. Any PL/SQL gurus out there?

Comment