oracle 如何在 where 条件下使用计算列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2416522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:10:31 来源:igfitidea点击:
How to use a calculated column in where condition?
提问by Sachin Chourasiya
How to use a calculated column in the where
condition in Oracle 9i?
如何where
在Oracle 9i中的条件中使用计算列 ?
I want to use something like
我想使用类似的东西
select decode (:pValue,1,
select sysdate from dual,
select activation_date from account where AcNo = 1234) as calDate
where caldate between startDate and endDate;
回答by Tony Andrews
You can use an in-line view:
您可以使用内嵌视图:
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;
回答by R. Genaro
You could select your date from dual and join the results:
您可以从 Dual 中选择您的日期并加入结果:
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