搜索查询中的日期为空
这是一个简单的问题,但我现在不知道该怎么做。
我在搜索查询中有一个日期字段。查询不是动态的,否则这会更容易。我需要能够返回与输入日期匹配的记录,或者如果未输入日期,则应返回所有记录。
这就是我所拥有的,但它不起作用。无论是否存在条件,它都不会返回任何行。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过:
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
只需写下你的条件,如下所示:
just write your where condition like this:
怎么样:
假设 table.dateField 不包含空值。如果是,则可能:
假设 SYSDATE+10000 不是您数据中的值。
How about:
Assuming table.dateField does not contain nulls. If it does, then perhaps:
Assumes that SYSDATE+10000 is a value not in your data.
我会尝试在 OR 部分使用 NVL 子句:
I would try using an NVL clause in the OR section: