Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个文本框,我可以从用户那里获取开始和结束日期。这里有3个条件。
最后,我的查询应该是什么?
变量:start_date和end_date
start_date
end_date
询问:SELECT * FROM kkmail WHERE MAIL_DATE ....
SELECT * FROM kkmail WHERE MAIL_DATE ....
SELECT * FROM kkmail WHERE (MAIL_DATE >= @start_date OR @start_date is null) and (MAIL_DATE <= @end_date OR @end_date is null)
Oracle 具有LNNVL功能,可以简洁地编写这些类型的查询,虽然有点混乱。
SELECT * FROM kkmail WHERE lnnvl(mail_date < @start_date) AND lnnvl(mail_date > @end_date);
Demo