Oracle SQL:如果我在日期字段上进行比较操作员,我仍然需要一个不为null

发布于 2025-02-13 17:04:55 字数 35 浏览 0 评论 0原文

如果我要在日期字段上进行比较操作员(>,,, =)

If I am doing a comparison operator (>, <, =) on a date field do I also need a IS NOT NULL on the date field

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书间行客 2025-02-20 17:04:55

如果我正确理解您,那就不 - 您不必检查它是否不是null。

例如(今天是日期'2022-07-07',2022年7月7日):

SQL> with test (id, date_column) as
  2    (select 1, date '2022-05-25' from dual union all  -- before today
  3     select 2, date '2022-12-13' from dual union all  -- after today
  4     select 3, null              from dual            -- unknown, as there's no value in DATE_COLUMN
  5    )
  6  select *
  7  from test
  8  where date_column >= sysdate;

        ID DATE_COLUM
---------- ----------
         2 2022-12-13

SQL>

如果您包括而不是null null 检查,您将获得相同的结果:

<snip>
  6  select *
  7  from test
  8  where date_column is not null
  9    and date_column >= sysdate;

        ID DATE_COLUM
---------- ----------
         2 2022-12-13

SQL>

If I understood you correctly, then no - you don't have to check whether it is not null.

For example (today is date '2022-07-07', 7th of July 2022):

SQL> with test (id, date_column) as
  2    (select 1, date '2022-05-25' from dual union all  -- before today
  3     select 2, date '2022-12-13' from dual union all  -- after today
  4     select 3, null              from dual            -- unknown, as there's no value in DATE_COLUMN
  5    )
  6  select *
  7  from test
  8  where date_column >= sysdate;

        ID DATE_COLUM
---------- ----------
         2 2022-12-13

SQL>

If you include the not null check, you'll get the same result:

<snip>
  6  select *
  7  from test
  8  where date_column is not null
  9    and date_column >= sysdate;

        ID DATE_COLUM
---------- ----------
         2 2022-12-13

SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文