搜索查询中的日期为空

发布于 2024-10-20 16:21:07 字数 589 浏览 2 评论 0原文

这是一个简单的问题,但我现在不知道该怎么做。

我在搜索查询中有一个日期字段。查询不是动态的,否则这会更容易。我需要能够返回与输入日期匹配的记录,或者如果未输入日期,则应返回所有记录。

这就是我所拥有的,但它不起作用。无论是否存在条件,它都不会返回任何行。

AND ( (table.dateField = p_dateField) 
   OR (table.dateField = table.dateField and table.dateField is null))

提前致谢。

经过一个小时的使用后,我想出了这个:

and (  
      ( p_dateField IS NOT NULL AND table.dateField = p_dateField)
         OR ( p_dateField IS NULL AND (table.dateField is null or (table.dateField is not null))
     )

它适用于我能够对其进行的少数测试。如果有人可以建议更好的方法,请这样做。

谢谢!

this is a easy question but I can't think of how to do this at the moment.

I have a date field in search query. The query isn't dynamic or this would be easier. I need to be able to return the records that match the date entered or if the date isn't entered then it should return all.

This is what I have but it isn't working. It's not returning any rows, when there is criteria or when there isn't.

AND ( (table.dateField = p_dateField) 
   OR (table.dateField = table.dateField and table.dateField is null))

thanks in advance.

After an hour of working with it I came up with this:

and (  
      ( p_dateField IS NOT NULL AND table.dateField = p_dateField)
         OR ( p_dateField IS NULL AND (table.dateField is null or (table.dateField is not null))
     )

It works for the few tests I've been able to run against it. If anyone can suggest a better method please do.

Thanks!

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

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

发布评论

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

评论(4

超可爱的懒熊 2024-10-27 16:21:07

您是否尝试过:

AND ((table.dateField = p_dateField AND NOT(p_dateField is NULL))
或者 p_dateField 为 NULL)

我假设 p_dateField 是 Date 参数

Have you tried:

AND ( (table.dateField = p_dateField AND NOT(p_dateField is NULL))
OR p_dateField is NULL)

I am assuming that p_dateField is the Date parameter

猫七 2024-10-27 16:21:07

只需写下你的条件,如下所示:

where previous_conditions
  AND ((table.dateField = p_dateField) or (p_dateField is null))
  and other_conditions;

just write your where condition like this:

where previous_conditions
  AND ((table.dateField = p_dateField) or (p_dateField is null))
  and other_conditions;
九厘米的零° 2024-10-27 16:21:07

怎么样:

AND table.dateField = NVL(pdateField, table.dateField)

假设 table.dateField 不包含空值。如果是,则可能:

AND NVL(table.dateField, SYSDATE+10000) = 
        NVL(pdateField, NVL(table.dateField, SYSDATE+10000)

假设 SYSDATE+10000 不是您数据中的值。

How about:

AND table.dateField = NVL(pdateField, table.dateField)

Assuming table.dateField does not contain nulls. If it does, then perhaps:

AND NVL(table.dateField, SYSDATE+10000) = 
        NVL(pdateField, NVL(table.dateField, SYSDATE+10000)

Assumes that SYSDATE+10000 is a value not in your data.

牵强ㄟ 2024-10-27 16:21:07

我会尝试在 OR 部分使用 NVL 子句:

AND ( (table.dateField = p_dateField) 
      OR (NVL(p_datefield, to_date('01/01/1901','MM/DD/YYYY')) =
           to_date('01/01/1901,'MM/DD/YYYY')))

I would try using an NVL clause in the OR section:

AND ( (table.dateField = p_dateField) 
      OR (NVL(p_datefield, to_date('01/01/1901','MM/DD/YYYY')) =
           to_date('01/01/1901,'MM/DD/YYYY')))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文