Oracle 日期与大小写的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5555321/
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 23:16:13  来源:igfitidea点击:

Oracle date difference with case

sqloracledate-arithmetic

提问by CFNinja

I have the following:

我有以下几点:

 select nvl ( 
     (select 1
      from tableA, tableB 
      where tableA.id(+) = 9999
      and tableB.project_id(+) = tableA.project_id
      and sysdate - tableA.start_date < 120), 0) as myFlag from dual;

I am trying to see if the project start date is less than 120 or not. The above query works but is there a better way of doing this? Like with a case statement?

我想看看项目开始日期是否小于 120。上面的查询有效,但有没有更好的方法来做到这一点?就像一个案例陈述?

回答by Erkan Haspulat

select 
  case 
      when sysdate-tableA.start_date < 120 then 1
      else 0
  end myFlag
from tableA, tableB 
where tableA.id(+) = 9999
and tableB.project_id(+) = tableA.project_id

回答by N West

Why are you left joining to table B? Couldn't you just do this?

你为什么要加入B桌?你不能这样做吗?

SELECT CASE WHEN ID IS NULL THEN 0 ELSE 1 END
FROM TableA 
WHERE sysdate - TableA.start_date < 120 and TableA.id = 9999;