[英]using if-else/decode in where clause
我有一个具有多个条件的游标,用于检索一组数据。 我最近在其中添加了日期条件,以检索用户输入的特定日期之间的数据,如下所示:
cursor c1
is
select t.*
from (select v.*, dense_rank () over (order by created desc)
as rank
from test.table_v2 v
where some condition
and some condition
and some condition
and some condition
and some condition
and some condition
and ((ended) between to_date(sd,'mm/dd/rrrr')
and to_date(sd,'mm/dd/rrrr')+3
or ended like decode(sd,null,'%')) --new condition
and some condition
) t
where rank < rmax+1
order by ended desc;
此处rmax = 1000
我需要在where子句中添加一个条件,以便当sd(用户输入的日期)为null时,行被限制为1000,而当其为非null时,则不应考虑行限制。
我不确定解码是否可以在where子句中使用。 有什么办法吗?
只需添加or sd is [not] null
select t.*
from (select v.*, dense_rank () over (order by created desc)
as rank
from test.table_v2 v
where some condition
and some condition
and some condition
and some condition
and some condition
and some condition
and (ended between to_date(sd,'mm/dd/rrrr')
and to_date(sd,'mm/dd/rrrr')+3
or sd is null) --new condition
and some condition
) t
where rank < rmax+1 or sd is not null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.