2017-09-01 24 views
1

的想法是,我有一个临时表:选择返回不同的表,基于其他表的条件在甲骨文

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#) 

而且我对如何做这样真正巨大的问题,因为,其实我的主要选择是从NOTHING,只有那些内有一些表。另一方面,我不能使用双列,因为列和行数可能有所不同。有任何想法吗?

+1

我的建议是将表格标准化并摆脱CSV数据。它会使查询和维护成为一场噩梦。 –

+0

@TimBiegeleisen不幸的是,这个Sources列是在groupby期间生成的,我无法对此做任何事情。 – tweant

回答

0

如果列可能不同,那么这在SQL中是不可能的。您必须在应用程序级别解决它。当用户点击帐单时,请从table_illings中选择,否则从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# 

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

0

您可以为发票,帐单等单独制作交互式报告,并使用“页面项P1_TYPE的值为X”形式的服务器端条件对所选类型有条件地进行适当渲染。

+0

我无法做到这一点,因为该查询已在现有的交互式报告中使用,插件嵌套报告。 – tweant