如何在哪里条件下使用计算列?

时间:2010-03-10 11:40:36

标签: sql oracle calculated-columns oracle9i

如何在Oracle 9i的where条件中使用计算列?

我想使用像

这样的东西
select decode (:pValue,1,
               select sysdate from dual,
               select activation_date from account where AcNo = 1234) as calDate
where caldate between startDate and endDate;

2 个答案:

答案 0 :(得分:9)

您可以使用内嵌视图:

select calcdate from
(
select startDate, endDate,
       decode (:pValue,1,
               select sysdate from dual,
               select activation_date from account where AcNo = 1234) as calcdate
)
where calcdate between startDate and endDate;

答案 1 :(得分:3)

您可以从双重选择日期并加入结果:

select * 
from   <<your table with startDate and endDate columns>> -- Since you ommited the main "from" clause from your statement
,      (
         select decode( :pValue
                      , 1, sysdate
                      , ( select activation_date from account where AcNo = 1234 )
                      ) as calDate
         from   dual
       ) c
where  c.calDate between startDate and endDate
... -- any other conditions you may need