Method to use the query of an Interactive Report, including all user defined filters, sort orders, etc., in a pl/sql procedure.
Change the settings of the IR and then click the Run Procedure button to see the results of the pl/sql procedure.
A similar (but more complex) method to get the query of a Classic Report can be found on the
Get Classic Report query page.
Note 1: Make sure the columns you use in your code are always present in the query result. In this example, columns EMPNO and JOB are used in the code and therefore these columns are set "not hide-able" for the user.
Note 2:
In recent Apex versions the apex_ir.get_report function has been deprecated - thanks to Yuri for pointing out that one!
The documentation states that you should use apex_region.open_query_context instead, but that is not really a 1-on-1 replacement... This post gives an example of a way of using that:
https://srihariravva.blogspot.com/2021/10/interactive-grid-process-filtered-data.html
Note 3: I haven't found a way to get columns that are hidden from the user to still be included in the resulting query.
In the example I have tried a hidden column, 2 columns that are not shown because of server-side conditions, and a column that is not shown because of an authorization scheme.
None of these are included in the resulting query, excpet for the Hidden column - and that one is excluded in the final select statement, so that doesn't help.
This can be annoying but it also seems logical - if columns are not needed in the final result, there is simply no reason to include them. Unless you want to use them for something else of course, in which case you seem to be out of luck here.
Yuri tried to show hidden columns with the apex_region.open_query_context option mentioned above, but that seems to behave in the same way - hidden columns are not included.
The only thing I can think of next is to fill a collection first (including all the "hidden" columns), and then use that to both show the report AND access the hidden columns too. That's not elegant of course, but it could work.