将参数传递给Oracle中的WITH子句查询

时间:2016-11-24 08:49:51

标签: oracle with-clause

我想知道是否可以将一个或多个参数传递给WITH子句查询;以一种非常简单的方式,做这样的事情(显然,taht不起作用!):

with qq(a) as (
  select a+1 as increment 
    from dual
)
select qq.increment 
  from qq(10); -- should get 11

当然,我要做的事情要复杂得多,因为with子句应该在子查询中,而且我传递的参数是从主查询获取的值... .details应要求......; - )

感谢任何提示

1 个答案:

答案 0 :(得分:0)

好的.....这是完整的交易:

select appu.* from 
(<quite a complex query here>) appu
where not exists 
      (select 1 
             from dual 
             where appu.ORA_APP IN 
                   (select slot from 
                      (select distinct slots.inizio,slots.fine from 
                            (
                             with 
                             params as (select 1900 fine from dual)
                             --params as (select app.ora_fine_attivita fine 
                             -- where app.cod_agenda = appu.AGE
                             -- and app.ora_fine_attivita = appu.fine_fascia
                             --and app.data_appuntamento = appu.dataapp
                             --)
                             , 
                             Intervals (inizio, EDM) as
                             ( select 1700, 20 from dual
                             union all
                             select inizio+EDM, EDM from Intervals join params on 
                             (inizio <= fine)
                             )
                             select * from Intervals join params on (inizio <= fine)
                       ) slots
                    ) slots
        where slots.slot <= slots.fine
      )
      order by 1,2,3;

如果没有深入细节,where条件应该删除那些'appu.ORA_APP'匹配应该在(外部)'slot'表中创建的记录之一的记录。 示例中使用的常量适用于记录的子集(单个'appu.AGE'值),这就是我应该对其进行参数化的原因,以便使用注释的'params'表(然后在其中复制) '间隔'表。

我知道从头开始分析并不简单,但我尽量让它尽可能清晰;如果需要,请随时询问数字示例.... 感谢