根据 Oracle 中其他 table 中的条件选择返回不同的 table

Selects returning different tables based on condition in other table in Oracle

想法是我有一个临时的table:

Type     | Sources
Invoices | 44,22,11
Billings | 99,90,12,34

在我的应用程序(交互式报告中带有交互式报告的顶点)中,用户单击一行图标:账单发票。在我的 plsql 查询中,我得到值 #type##sources# 作为结果(它们将由顶点注入适当的值)。我想实现这样的目标:

select
    case when #type# = 'Billings'
        then (select from table_billings where table_billings.sources = #sources#)
    when #type# = 'Invoices'
        then (select from table_invoices where table_invoices.sources = #sources#)

而且我对如何这样做真的有很大的问题,因为实际上我的主要 select 来自 NOTHING,只有内部的有一些 table秒。另一方面,我不能使用 from dual,因为列数和行数可能会有所不同。有什么想法吗?

如果列可能不同,那么这在 SQL 中是不可能的。您必须在应用程序级别解决它。当用户点击 billings 然后 select 从 table_billings 否则从 table_invoices.

但是,如果您可以统一通用输出列,那么您可以使用联合,例如::

select col1, col2, col3 
  from table_billings
  where #type# = 'Billings' and sources = #sources#
union all
select colA, colB, colC 
  from table_invoices
  where #type# = 'Invoices' and sources = #sources#

两个表的输出列必须是同一类型。

您可以为发票、帐单等创建单独的交互式报告,并使用 "value of page item P1_TYPE is X".

形式的服务器端条件有条件地只呈现适合所选类型的报告