0
votes

IR based on PL/SQL Function Body returning SQL Query.

How do i can create Interactive reports based on multiple table and Deferent column name.

Exp :- Select list item return three value 1 or 2 or 3

And the function return query basen on select list value

when Value equal 1

Select name, satate, country_id from cities

when value equal 2 Return

Select country, id from country

when value equal 3 Return

Select ocean,oc_id,from oceans

The three query return different column name and value.

2

2 Answers

1
votes

Ok firstly, your question is poorly written. But from what I gather, you want an SQL query that returns different things based on an input.

I dont think you even need a plsql function body for this.

Simply do something like this:

SELECT * FROM
(SELECT name as name,
       state as state,
       country_id as id,
       1 as value
  FROM cities
UNION ALL
SELECT country as name,
       NULL as state,
       id as id,
       2 as value
  FROM country
UNION ALL
SELECT ocean as name,
       NULL as state,
       oc_id as id,
       3 as value
  FROM oceans)
 WHERE value = :input_parameter_value;

Because if you are trying to display a variable number of columns and constantly changing their names and such. You are gonna have a bad time, it can be done, as can everything. But afaik its not exactly simple

1
votes

No objections to what @TineO has said in their answer, I'd probably do it that way.

Though, yet another option: if your Apex version allows it, you can create three Interactive Report regions on the same page, each selecting values from its own table, keeping its own column labels.

Then create a server condition for each region; its type would be Function that returns a Boolean and look like

return :P1_LIST_ITEM = 1;

for the 1st region; = 2 for the 2nd and = 3 for the 3rd.

When you run the page, nothing would be displayed as P1_LIST_ITEM has no value. Once you set it, one of conditions would be met and appropriate region would be displayed.